+1

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

4/7/2019 1:41:46 PM

Krishna Kumar

8 Answers

New Answer

+8

Krishna Kumar Then, you don't need that input field! ⟹ Make sure order of format and variable data types match up. Go through the lesson again, you'll better understand and use Daljeet Singh 's advice!

+8

Hello, 😊 If you need help you can post the code you are struggling with!  • SEARCH for similar QUESTIONS or ANSWERS before posting  • Include relevant TAGS  • https://www.sololearn.com/post/75089/?ref=app  • https://code.sololearn.com/WvG0MJq2dQ6y/

+8

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!!

+4

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

+3

Your scanf() has four format specifiers (%d, %f etc.) for three variables

+3

Krishna Kumar add this (might come handy in future) to you code* char text[5]="abcd"; printf("%8s\n",text); printf ("%*s\n",0xf, text);

+2

Danijel, but what if we don't want to skip the input float field and still print the values of x and y?

+1

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.