Learn how to form strings using one-dimensional array String manipulation functions: strcpy strrev strcmp Program using strings
char name[3] = {‘A', ‘L', ‘\0’}; ‘A’ ‘L’ ‘\0’ name[0] name[1] name[2]
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]
char word[ ] = {“Hello” };
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);
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; }
int main() { char hisName[25]; cout > hisName; cout << "Hello " << hisName << endl;
char myName[25]; strcpy(myName, "Helen"); //cannot write: myName = “Helen”;
‘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’...
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]
if ( hisName == myName) {... }
x = strcmp ( hisName, myName);
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; }
Learn how to form strings using one-dimensional array String manipulation functions: strcpy strrev strcmp Program using strings