/* This program demonstrates c-strings * a c-string is an array of chars. * chars are still integer types. When we store a character in a variable or as an array * element, it stores the equivalent ASCII value of that character, as an integer * So, we can do math with characters, since they are internally numbers. * * This program shows us the 4 main functions for c-string * 1. Finding the length of a string: strlen * 2. Copying strings: strcpy * 3. concatenating strings: strcat * 4. Comparing strings: strcmp * * We also implement strcpy ourselves, to understand how it works */ #include #include using namespace std; void stringCopy(char st1[], char st2[]); int main() { char str[200]; char copy[200]; cout<<"Enter a string: "; cin.getline(str, 200, '#'); cout<<"Enter another string: "; cin.getline(copy, 200); cout<<"You entered: "< Patrick is "first" P < S * Spongebob , patirck -> Spongebob is "first", S < p * Spongebob, 4atrick -> 4atrick is "first", numeral < letters * Spongebob, Sqiudward -> Spongebob is "first" S==S, p Square is first, first 3 letters are the same, a < i * Squid, Squidward -> Squid is "first", all letters matched until "Squid" ran out of letters * Squid Squid -> strings are equal */ cout<<"Demonstrating strcmp for string comparison:\n"; char str2[100]; cout<<"Enter a string to compare: "; cin.getline(str2,100); int diff = strcmp(str, str2); if (diff < 0) cout< 0) cout<