2016-07-15 53 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