Why there is no output of the following code?
scanf("%2d%d%f%5s", &x, &y, text); printf ("%d %d %s", x, y, text) ; // where x and y are integer variables and text is character type array We've input as 1234 5.7 elephant
Krishna Kumar You should correct the scanf() function for floating data type: %f scanf("%2d %d %*f %5s", &x, &y, text); • A format specifier can include several options along with a conversion character: %[*][max_field]conversion character ⟹ The optional * will skip the input field!!
Krishna Kumar read about format specifiers here : https://www.geeksforgeeks.org/format-specifiers-in-c/ in your code you are using %d instead use %s // try inserting code by clicking @ "insert code" https://code.sololearn.com/c3e7aVZ96l1P/?ref=app
Your scanf() has four format specifiers (%d, %f etc.) for three variables
Krishna Kumar add this (might come handy in future) to you code* char text="abcd"; printf("%8s\n",text); printf ("%*s\n",0xf, text);
Danijel, but what if we don't want to skip the input float field and still print the values of x and y?
But here scanf("%2d%d%f",&x,&y); printf ("%d",x); printf("\n%d",y); //it also has greater format specifiers(3) as compared to lesser variables (2) but it gives output! Here x and y are also integer type.