# include
Int main ()
{
int c;
While ((c=getchar ())!=(EOF)
If (c=='1')
Printf (" Hello, nice to meet you. ");
Else if (c=='2')
Printf (" My name is world. ");
Else if (c=='3')
Printf (" What 's your name?" );
The else
putchar(c);
}
If I change this program to
# include
Int main ()
{
int c;
While ((c=getchar ())!=(EOF)
If (c=='hi')
Printf (" Hello, nice to meet you. ");
Else if (c=='name')
Printf (" My name is world. ");
Else if (c=='3')
Printf (" What 's your name?" );
The else
putchar(c);
}
Then the output will be
Hi
Hi
The name
The name
3
What's your name?
CodePudding user response:
Chat c [256];//stringWhile (gets (c)!=NULL) {//receiving string
If (STRCMP (c, "hi")==0)//string comparison
Printf (XXX)
.
}
CodePudding user response:
Input statement, it is the string handling, string handling can refer to: the fgets, STRCMP, strcpy, and so on functionelse if (c=='name')
The name should be a string here, 'name' is illegal, should use STRCMP string comparison
CodePudding user response:
Getchar () can only obtain a single characterCodePudding user response:
The scanf, STRCMP