如何正確查看在我的scanf函數中讀取了多少個輸入?當我運行下面的代碼不顯示的結果,這是因爲我沒有2個輸入從scanf或其他一些原因 讀到這裏是我的代碼:如何正確驗證在scanf中讀取了多少個輸入
#include <stdio.h>
int main()
{
float numberOne;
float numberTwo;
scanf("%f %f", &numberOne, &numberTwo);
float result = numberOne + numberTwo;
int howManyRead = scanf("%f %f", &numberOne, &numberTwo);
if (howManyRead == 2)
{
printf("%f", &result);
}
else
{
printf("invalid input");
}
sleep(10);
}
https://stackoverflow.com/questions/10469643/value-returned-by-scanf-function-in-c希望這可以幫助。 – Mare70
您是否打算兩次撥打scanf? – user2867342
「在我的scanf函數中讀取了多少輸入?」 - >您希望用戶如何表明輸入已完成?通過輸入文本,然後輸入''\ n''?應該輸入'「123 \ n」'報告只輸入了1個數字還是等待輸入的下一行如「456 \ n」'? – chux