+ 2
Consider following 2 codes inside main function.đđđ why output is different in both the cases????
char arr[50],ch; scanf("%s",arr); scanf ("%c",&ch); printf("%s %c",arr,ch); or char arr[50],ch; scanf("%s %c",arr,&ch); printf("%s %c",arr,ch); Output of 1st is = arr Output of 2nd is=arr ch
5 Respostas
+ 3
char arr[50],ch;
scanf("%s",arr);
scanf ("%c",&ch);
//here the remaining \n new line character is assigned to ch.
How to avoid this:
char arr[50],ch;
scanf("%s\n",arr);
scanf ("%c",&ch);
That should be equivalent to your second code.
+ 3
This is one of the many problems with scanf(). You should avoid the scanf() functions whenever you can, and use fgets() and getchar() instead.
+ 2
due to white space in the buffer memory.
Second scanf scans the white space and prints the whitespace.
char arr[50],ch;
scanf("%s",arr);
scanf(" %c",&ch);
printf("%s %c",arr,ch);
Will work like second one
because space before %c will skip the white space in buffer memory
+ 2
Kevin â
/[inactive]??/ thanks bro...
0
Sameer Crestha please see again que.. and then Kevin's answer......