So I'm trying to get a scanf
to accept strings and store it which will not carry into the next scanf
. I'm quite new to C.
For example:
#include <stdio.h>
#include <stdlib.h>
int main(){
char word1[100];
char word2[100];
printf("Enter a sentence:");
scanf("%[^\n]s",&word1);
printf("Enter a second sentence:");
scanf("%[^\n]s",&word2);
printf("%s %s",word1,word2);
return 0;
}
But it'll display this:
Enter a sentence:I am
Enter a second sentence:I am P)Γ
Press Enter to return to Quincy...
What I want it to display is:
Enter a sentence:I am
Enter a second sentence: bread !
I am bread!
Any advice?