Presentation is loading. Please wait.

Presentation is loading. Please wait.

 Learn how to form strings using one-dimensional array  String manipulation functions:  strcpy  strrev  strcmp  Program using strings.

Similar presentations


Presentation on theme: " Learn how to form strings using one-dimensional array  String manipulation functions:  strcpy  strrev  strcmp  Program using strings."— Presentation transcript:

1

2

3  Learn how to form strings using one-dimensional array  String manipulation functions:  strcpy  strrev  strcmp  Program using strings

4 char name[3] = {‘A', ‘L', ‘\0’}; ‘A’ ‘L’ ‘\0’ name[0] name[1] name[2]

5 char word[6] = {'H','e','l','l','o',‘\0'}; char word[6] = {"Hello"}; ‘H’ ‘e’ ‘l’ ‘o’ word[0] word[1] word[2] word[3] word[4] ‘\0’ word[5]

6 char word[ ] = {“Hello” };

7 int main() { char hisName[25]; cout > hisName; cout << "Hello " << hisName << endl; char myName[25]; strcpy(myName, "Helen"); strrev(hisName); cout << "My name is " << myName << " Your name reversed is " << hisName << endl; strrev(hisName);

8 int x = strcmp(hisName, myName); if (x == 0) cout << "Hey, my name is the same as yours!"; else if (x < 0) cout << "Your name comes before mine alphabetically"; else cout << "Your name comes after mine alphabetically"; cout << endl; return 0; }

9 int main() { char hisName[25]; cout > hisName; cout << "Hello " << hisName << endl;

10 char myName[25]; strcpy(myName, "Helen"); //cannot write: myName = “Helen”;

11 ‘S’ ‘a’ ‘m’ ‘\0’ hisName[0] hisName[1] hisName[2] hisName[3]... ‘\0’ his Name[24] ‘H’ ‘e’ ‘l’ ‘e’ ‘n’ myName[0] myName[1] myName[2] myName[3] myName[4] ‘\0’ myName[5] myName[24] ‘\0’...

12 strrev(hisName); cout << "My name is " << myName << " Your name reversed is " << hisName << endl; strrev(hisName ); ‘m’ ‘a’ ‘S’ ‘\0’ hisName[0] hisName[1] hisName[2] hisName[3]... ‘\0’ his Name[24]

13 if ( hisName == myName) {... }

14 x = strcmp ( hisName, myName);

15 int x = strcmp(hisName, myName); if (x == 0) cout << "Hey, my name is the same as yours!"; else if (x < 0) cout << "Your name comes before mine alphabetically"; else cout << "Your name comes after mine alphabetically"; cout << endl; return 0; }

16  Learn how to form strings using one-dimensional array  String manipulation functions:  strcpy  strrev  strcmp  Program using strings


Download ppt " Learn how to form strings using one-dimensional array  String manipulation functions:  strcpy  strrev  strcmp  Program using strings."

Similar presentations


Ads by Google