2016-07-15 54 views
-6

我想讀1個字符和2個整數沒有成功。閱讀1個char和2個整數與scanf函數

的C代碼:

char action; int cr,cc; 
printf("Enter 'c <row> <column>' to click on a block.\n"); 
scanf("%c %d %d",&action,&cr,&cc); 
printf("You typed: %c %d %d\n",action,cr,cc); 

端子輸出:(實施例)

Enter 'c <row> <column>' to click on a block. 
c 3 3 
You typed: 
0 0 

我用gcc編譯它(Ubuntu的5.3.1-14ubuntu2.1)5.3.1 20160413在Ubuntu 16.04 LTS 。

+0

請附上您的變量的聲明 – Fazlin

+2

嘗試'的scanf( 「%C%d%d」,&行動,與CR,&cc);' – BLUEPIXY

+0

http://stackoverflow.com/questions/38343113/why-is-the-below-代碼未掃描所有的投入,正確#comment64105936_38343113 –

回答

0

沒有見過你的整個代碼,我建議你試試:

#include<stdio.h> 

int main(int argc, char *argv[]) 
{ 
     int cr, cc; 
     char action; 
     printf("Enter 'c <row> <column>' to click on a block.\n"); 
     scanf("%c %d %d",&action, &cr, &cc); 
     printf("You typed: %c %d %d\n", action, cr, cc); 
} 

這應該工作。

+1

如我愛你這樣做......有什麼區別? – GeoMint

+0

你能提供有關環境的更多信息?編譯器?平臺?也許仍然發佈完整的示例源代碼? – inzanez