I'm confused about how exactly the string functions (strcat, etc.) work. I honestly just don't understand them at all, although more specifically, I don't understand how or what the string functions do in the following code example that they give:
If someone could please explain it to me a bit better than they do here, I would greatly appreciate it.Code:#include <iostream> //For cout #include <cstring> //For the string functions using namespace std; int main() { char name[50]; char lastname[50]; char fullname[100]; // Big enough to hold both name and lastname cout<<"Please enter your name: "; cin.getline ( name, 50 ); if ( strcmp ( name, "Julienne" ) == 0 ) // Equal strings cout<<"That's my name too.\n"; else // Not equal cout<<"That's not my name.\n"; // Find the length of your name cout<<"Your name is "<< strlen ( name ) <<" letters long\n"; cout<<"Enter your last name: "; cin.getline ( lastname, 50 ); fullname[0] = '\0'; // strcat searches for '\0' to cat after strcat ( fullname, name ); // Copy name into full name strcat ( fullname, " " ); // We want to separate the names by a space strcat ( fullname, lastname ); // Copy lastname onto the end of fullname cout<<"Your full name is "<< fullname <<"\n"; cin.get(); }



LinkBack URL
About LinkBacks




