Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Baisc String Functions ...
Index -> Programming, C++ -> C++ Tutorials
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Kuntzy




PostPosted: Thu Jan 29, 2004 8:32 pm   Post subject: Baisc String Functions ...

C++ supports many different string (declarde as an array of characters), i'm gonna hit the most common ones.

strcpy()
a call to strcpy() takes this form:
code:
strcpy (to, from);

The strcpy() function will take the contents of one string (from) and copy it into another (to). Take note though that the array you are copyin
g tomust be large enough to the contents of from, if not your array will over run.

strcat()
a call to strcat() takes this form:
code:
strcat(s1, s2);

A call to strcat() will tag the contents of s2 to the end of s1, and s2 will stay unchanged. Remember s1 must be large enough to hold both arrays.

strcmp()
a call to strcmp() takes this form:
code:
strcmp(s1, s2);

The strcmp is probably one of the most usefull functions in the tutorial, strcmp() will take the contents of s1 and s2 and compare them. If the to strings are exactly the same it will return a 0. If s1 one is greater than s2 (according to dictionary order), then it will return a positive number; if it is less a negative number is returned.

strlen()
a call to strlen() takes this form:
code:
strlen(s);

where 's' is a string. The strlen() returns a length of the string pointed to by 's'.

toupper(), tolower()
a call to these takes this form:
code:
toupper(string) or tolower(string)

This will take the character and returns its lower case eqivalent.

isupper(), islower()
these will return a boolean statement according to whether the character is upper or lower.
Sponsor
Sponsor
Sponsor
sponsor
Andy




PostPosted: Thu Jan 29, 2004 8:55 pm   Post subject: (No subject)

those become practically useless once u hit the string class
Kuntzy




PostPosted: Sat Jan 31, 2004 10:39 am   Post subject: (No subject)

I believe I did title the tutorial with the word BASIC in it.
McKenzie




PostPosted: Sat Jan 31, 2004 11:16 am   Post subject: (No subject)

I would edit the C++ and put C, then Dodge's post will look silly (I'll have to edit mine later perhaps I'll explain other fun C string functions like strstr (fun because of the name, and who doesn't like char *) and strrev (I love seeing palendrome example on compsci that don't use it)
AsianSensation




PostPosted: Sat Jan 31, 2004 12:43 pm   Post subject: (No subject)

Kuntzy wrote:
I believe I did title the tutorial with the word BASIC in it.


Where? Where, all I saw was "Baisc String Functions". lol. Laughing

and I here I thought strstr would be a more popular function, seeing how close it is to turing's index without hitting the string classes.
McKenzie




PostPosted: Sat Jan 31, 2004 5:40 pm   Post subject: (No subject)

The fact that string-string returns a pointer causes a lot of Hit Wall
Kuntzy




PostPosted: Sat Jan 31, 2004 5:44 pm   Post subject: (No subject)

I just made this, becuase when I started doing simple console applications in C++, it would have helped me to see this ... guess i just suck at writing tutorials Embarassed
McKenzie




PostPosted: Sat Jan 31, 2004 5:51 pm   Post subject: (No subject)

Don't be so hard on yourself. Depending on the compiler there is a good chance that the string class is not even available. I know a lot of schools prefer to use the old Borland DOS compiler because it allows you to focus on the elements of the language without getting distracted by the IDE overhead in Visual Editors.
Sponsor
Sponsor
Sponsor
sponsor
Andy




PostPosted: Sat Jan 31, 2004 6:49 pm   Post subject: (No subject)

i cant believe u made us suffer through the pains of normal C strings first sir... evil... o btw read your rating on www.ratemyteacher.ca
McKenzie




PostPosted: Sat Jan 31, 2004 6:52 pm   Post subject: (No subject)

From a learning point of view I like them. Good to drive home arrays and introduce pointers. From a programming point of view I always hated them myself.
Display posts from previous:   
   Index -> Programming, C++ -> C++ Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 10 Posts ]
Jump to:   


Style:  
Search: