错误的输出显示使用结构(Wrong output display With Structures)
我试图在C程序中执行以下结构,但它不起作用。 它不能正确打印给定值。
#include<stdio.h> #include<conio.h> int main() { struct book { char name; int page; float price; }; struct book b1, b2, b3; clrscr(); printf("\n 1st data \n"); scanf("%c%f%d",&b1.name,&b1.price,&b1.page); printf("\n 2nd data"); scanf(" %c%f%d",&b2.name,&b2.price,&b2.page); printf("\n3rd data"); scanf("%c%f%d",&b3.name,&b3.price,&b3.page); printf("%c%f%d",b1.name,b1.price,b1.page); printf("%c%f%d",b2.name,b2.price,b2.page); printf("%c%f%d",b3.name,b3.price,b3.page); getch(); return 0; }每次我运行上面的代码,我得到不同的输出..其中一个是:: ....输出....
data p 1 2.2 s 2 3.3 p0.1000002.1.00000022015s-?.<00000000000000000000000000000e+15315872I 'm trying to execute the following structure in a C program but it's not working. It does not print the given values correctly.
#include<stdio.h> #include<conio.h> int main() { struct book { char name; int page; float price; }; struct book b1, b2, b3; clrscr(); printf("\n 1st data \n"); scanf("%c%f%d",&b1.name,&b1.price,&b1.page); printf("\n 2nd data"); scanf(" %c%f%d",&b2.name,&b2.price,&b2.page); printf("\n3rd data"); scanf("%c%f%d",&b3.name,&b3.price,&b3.page); printf("%c%f%d",b1.name,b1.price,b1.page); printf("%c%f%d",b2.name,b2.price,b2.page); printf("%c%f%d",b3.name,b3.price,b3.page); getch(); return 0; }Every time I run the above code, I get different output.. one of them is:: ....output....
data p 1 2.2 s 2 3.3 p0.1000002.1.00000022015s-?.<00000000000000000000000000000e+15315872最满意答案
在给出第二个输入之后,输入缓冲区可能会变满,因此它不接受第3个输入。 每次输入后尝试使用fflush(stdin)。
After giving the second input , the input buffers might get full and hence its not accepting the 3rd input . try using fflush(stdin) after every input .
更多推荐
发布评论