
-----------------------------------
Kuntzy
Thu Jan 29, 2004 8:32 pm

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:
 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:
 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:
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:
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:
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.

-----------------------------------
Andy
Thu Jan 29, 2004 8:55 pm


-----------------------------------
those become practically useless once u hit the string class

-----------------------------------
Kuntzy
Sat Jan 31, 2004 10:39 am


-----------------------------------
I believe I did title the tutorial with the word BASIC in it.

-----------------------------------
McKenzie
Sat Jan 31, 2004 11:16 am


-----------------------------------
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
Sat Jan 31, 2004 12:43 pm


-----------------------------------
I believe I did title the tutorial with the word BASIC in it.

Where? Where, all I saw was "Baisc String Functions". lol.  :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
Sat Jan 31, 2004 5:40 pm


-----------------------------------
The fact that string-string returns a pointer causes a lot of :wall:

-----------------------------------
Kuntzy
Sat Jan 31, 2004 5:44 pm


-----------------------------------
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 :oops:

-----------------------------------
McKenzie
Sat Jan 31, 2004 5:51 pm


-----------------------------------
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.

-----------------------------------
Andy
Sat Jan 31, 2004 6:49 pm


-----------------------------------
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
Sat Jan 31, 2004 6:52 pm


-----------------------------------
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.
