0

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

7th Apr 2019, 1:41 PM
Krishna Kumar
Krishna Kumar - avatar
8 Antworten
+ 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!
7th Apr 2019, 4:27 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 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/
7th Apr 2019, 2:12 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 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!!
7th Apr 2019, 4:13 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 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
7th Apr 2019, 3:21 PM
Daljeet Singh
Daljeet Singh - avatar
+ 3
Your scanf() has four format specifiers (%d, %f etc.) for three variables
7th Apr 2019, 1:58 PM
Anna
Anna - avatar
+ 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);
8th Apr 2019, 6:05 AM
Daljeet Singh
Daljeet Singh - avatar
+ 2
Danijel, but what if we don't want to skip the input float field and still print the values of x and y?
7th Apr 2019, 4:21 PM
Krishna Kumar
Krishna Kumar - avatar
+ 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.
7th Apr 2019, 2:33 PM
Krishna Kumar
Krishna Kumar - avatar