Strings
#include <iostream.h> //For cout
#include <string.h> //For many of the string functions
#include <stdio.h> //For gets
void main()
{
char name[50]; //Declare variables
char lastname[50]; //This could have been declared on the last line...
cout<<"Please enter your name: "; //Tell the user what to do
gets(name); //Use gets to input strings with spaces or just to get strings after the user presses enter
if(!strcmpi("Alexander", name)) //The ! means not, strcmpi returns 0 for equal strings
{ //strcmpi is not case sensitive
cout<<"That's my name too."<<endl; //Tell the user if its my name
}
else //else is used to keep it from always outputting cout<<"That's not my name."
{
cout<<"That's not my name."<<endl;
}
cout<<"What is your name in uppercase..."<<endl;
strupr(name); //strupr converts the string to uppercase
cout<<name<<endl;
cout<<"And, your name in lowercase..."<<endl;
strlwr(name); //strlwr converts the string to lowercase
cout<<name<<endl;
cout<<"Your name is "<<strlen(name)<<" letters long"<<endl; //strlen returns the length of the string
cout<<"Enter your last name:";
gets(lastname); //lastname is also a string
strcat(name, " "); //We want to space the two names apart
strcat(name, lastname); //Now we put them together,we a space in the middle
cout<<"Your full name is "<<name; //Outputting it all...
}