![](/img/trans.png)
[英]Basic c program doesn't continue after the final scanf in the function, scanf just keeps accepting input endlessly
[英]C Program will not continue after scanf function is executed
我有一個簡單的 C 程序,我用它來學習如何在未來的學校項目中使用 scanf()。 當我通過 linux 終端執行程序時,我必須使用 end 命令來結束程序,然后它會給我輸入的值。 我的代碼有問題嗎?
問題:scanf函數執行后,直到我使用end終端命令后才執行printf函數。
代碼
#include<stdio.h>
int main(void)
{
int a = 0;//declaring int a
printf("Type a value in: ");//asks for value
scanf("%d\n" , &a);//scans use input assigns value to a
printf("Your value is %d \n" , a);//prints value of a
return 0;//returns value to end program
}//end main
去掉 scanf 格式字符串中的“\\n”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.