Code runs but nothing is displayed it just shows the code is running until I manually stop it

huangapple go评论65阅读模式
英文:

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 &lt;stdio.h&gt;

int main()
{
   char name[20];

   printf(&quot;Enter your name: &quot;);
   scanf(&quot;%s&quot;, name);

   printf(&quot;Hello %s ... Let&#39;s have fun !!! You=X | Computer=O\n&quot;, 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. 在 printfscanf 之间插入 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.

huangapple
  • 本文由 发表于 2023年6月6日 13:18:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76411618.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定