#include <stdio.h> /* stdin, printf, and fgets */
#include <string.h> /* for all the new-fangled string functions */
#include <iostream.h>
void strip_newline( char *str, int size )
{
int i;
/* remove the null terminator */
for ( i = 0; i < size; ++i )
{
if ( str[i] == '\n' )
{
str[i] = '\0';
/* we're done, so just exit the function by returning */
return;
}
}
/* if we get all the way to here, there must not have been a newline! */
}
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 >> name, 50, stdin ;
/* see definition above */
strip_newline( name, 50 );
/* strcmp returns zero when the two strings are equal */
if ( strcmp ( name, "Mudassir" ) == 0 )
{
cout << "That's my Name too.\n" ;
}
else
{
cout << "That's not my Name.\n" ;
}
// Find the length of your name
cout << "Your Name Is " << strlen ( name ) <<" Letter Long !" <<endl ;
cout << "Enter your last Name : " ;
cin >> lastname, 50, stdin ;
strip_newline( lastname, 50 );
fullname[0] = '\0';
/* strcat will look for the \0 and add the second string starting at
that location */
strcat( fullname, name ); /* Copy name into full name */
strcat( fullname, " " ); /* Separate the names by a space */
strcat( fullname, lastname ); /* Copy lastname onto the end of fullname */
cout << "Your full Name Is : "<<fullname ;
getchar();
return 0;
}