英文:
Code runs but nothing is displayed it just shows the code is running until I manually stop it
问题
The code you provided is in C, and it seems like you're experiencing an issue where the program doesn't display anything after you delete everything following the "printf("Enter your name: ");" line. It's essential to retain the necessary parts of the code for it to work correctly.
Here's the corrected code:
#include <stdio.h>
int main()
{
char name[20];
printf("Enter your name: ");
scanf("%s", name);
printf("Hello %s ... Let's have fun !!! You=X | Computer=O\n", name);
}
Ensure that you keep the #include <stdio.h>
line at the beginning, and don't remove any of the quotation marks or semicolons. This code should work as expected in Visual Studio Code.
英文:
#include <stdio.h>
int main()
{
char name[20];
printf("Enter your name: ");
scanf("%s", name);
printf("Hello %s ... Let's have fun !!! You=X | Computer=O\n", name);
}
This code runs but does not display anything, however when I delete everything after printf("Enter your name: "); this code runs perfectly and displays "Enter your name:".I am running this code on visual studios code, can someone please help me. Thank you
I have tried everything possible but nothing worked
答案1
得分: 1
"This code runs but does not display anything" 这段代码可以运行,但没有显示任何内容。
It doesn't display anything because of (line) buffering. 这是因为(行)缓冲的原因,所以没有显示任何内容。
Insert fflush(NULL);
between printf
and scanf
, and it will start working as you expect. 在 printf
和 scanf
之间插入 fflush(NULL);
,它将开始按照您的期望工作。
英文:
> This code runs but does not display anything
It doesn't display anything because of (line) buffering.
Insert fflush(NULL);
between printf
and scanf
, and it will start working as you expect.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论