C语言1.基础语句, scanf
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 /* run this program using the console pauser or add your own getch, system("pause") or input loop */ 5 6 int main(int argc, char *argv[]) { 7 int a, b, c=0; 8 char d,e,f=0; 9 double double_data=0; 10 printf("scanf()测试输入3个整数\n"); 11 scanf("%d%d%d",&a,&b,&c); 12 printf("scanf用%%d 得到a=%d, b=%d, c=%d\n\n",a,b,c); 13 14 a=b=c=0; 15 printf("scanf()测试输入3个整数输入格式带','\n"); 16 scanf("%d,%d,%d",&a,&b,&c); 17 printf("如果输入参数也带','则不会有异常。a=%d, b=%d, c=%d\n\n",a,b,c); 18 19 20 printf("scanf()测试输入1,2\n"); 21 scanf("%d%*c%d",&a,&b); 22 printf("scanf用* %%c 能过滤',' 得到a=%d, b=%d\n\n",a,b); 23 24 printf("scanf()测试输入3个字符\n"); 25 getchar();//在使用%c时,之前的输入,回车符号\n ascii1 10也会影响到之后的输入, 所以建议这边加getchar(); 26 scanf("%c%c%c",&d,&e,&f); 27 printf("scanf用%%c 得到d=%d, e=%c, f=%c\n",d,e,f); 28 printf("scanf用%%c 得到d=%c, e=%c, f=%c\n\n",d,e,f); 29 30 printf("scanf()测试输入double类型数值3.1415\n"); 31 //getchar();//在使用%c时,之前的输入,回车符号\n ascii1 10也会影响到之后的输入, 所以建议这边加getchar(); 32 scanf("%f",&double_data); 33 printf("scanf用%%f 得到d=%f \n\n",double_data); 34 scanf("%lf",&double_data); 35 printf("scanf用%%lf 得到d=%lf \n\n",double_data); 36 37 38 return 0; 39 }