I tried to write a program that scans a string from a user and checks it, what the user enters, and if it is true, does something, and if it does nothing. The code I wrote looks like this:
#include<stdio.h>
#include<conio.h>
int main()
{
char string[20];
printf("Enter a sentence : ");
scanf("%s",&string);
if(strcmp(string,"what up")==0)
printf("\nNothing special.");
else
printf("\nYou didn't enter correct sentence.");
getch();
return 0;
}
but it does not work correctly. I think because the program cannot recognize the space when it wants to scan. What should I do? (I am new to c, so please explain what you did.)
source
share