- difference between scanf("%s",s) and scanf("%[^\n]s",s)
when we say for scanf("%[^\n]s",s) It will read a string composed of any character except \n. It will end the string at the first \n it encounters.
while when scanf("%s",s) it will read only the string upto first space.
for example
int main()
{
char str[100];
char s[100];
scanf(" %[^\n]s", str);
scanf("%s",s);
printf("%s\n", str);
printf("%s", s);
}
if we give the input as
lakshay saini (and press enter)
lakshay saini (and press enter )
so the result will be printed as
lakshay saini
lakshay