Author |
Message |
Kuntzy
|
Posted: 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:
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:
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:
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:
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
|
|
|
Andy
|
Posted: Thu Jan 29, 2004 8:55 pm Post subject: (No subject) |
|
|
those become practically useless once u hit the string class |
|
|
|
|
|
Kuntzy
|
Posted: 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
|
Posted: 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
|
Posted: 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.
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
|
Posted: Sat Jan 31, 2004 5:40 pm Post subject: (No subject) |
|
|
The fact that string-string returns a pointer causes a lot of |
|
|
|
|
|
Kuntzy
|
Posted: 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 |
|
|
|
|
|
McKenzie
|
Posted: 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
|
|
|
Andy
|
Posted: 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
|
Posted: 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. |
|
|
|
|
|
|