簡體   English   中英

執行scanf函數后C程序不會繼續

[英]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”。

請參見在 C 中的 scanf() 中使用“\\n”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM