为了账号安全,请及时绑定邮箱和手机立即绑定

c中有多个子函数时,不能正确接收输入的数字

c中有多个子函数时,不能正确接收输入的数字

C
话语and诺言1 2015-11-01 16:47:15
#include<stdio.h>void prog1_1(){int k;float x=3.6f;printf("[k=x]=%d [x]=%f [k]=%d\n",k=x,x,k);printf("[k=x]=%d [x]=%.1f [k]=%d\n",k=x,x,k);}void prog1_2(){char cData;int iNum;float fData;printf("\ninput a char:");scanf("%c",&cData);printf("cData的值是%c\n",cData);printf("cData占的内存为%d字节\n",sizeof(cData));printf("cData起始地址是Ox%x\n",&cData);printf("\ninput an integer:");scanf("%d",&iNum);printf("iNum的值是%d\n",iNum);printf("iNum占的内存为%d字节\n",sizeof(iNum));printf("iNum起始地址是%#x\n",&iNum);printf("\ninput a float:");scanf("%f",&fData);printf("fData的值是%f\n",fData);printf("fData占内存为%d字节\n",sizeof(fData));printf("fData的起始地址是Ox%p\n",&fData);}void prog7_1(){char c1,c2,c3;printf("Input three characters:\n");scanf("%c",&c1);scanf("%c",&c2);scanf("%c",&c3);printf("c1=%c\tASCII=%d\n",c1,c1);printf("c2=%c\tASCII=%d\n",c2,c2);printf("c3=%c\tASCII=%d\n",c3,c3);}void prog7_2(){int m,n;printf("输入两个数:\n");scanf("%d,%d",&m,&n);printf("m=%d,n=%d\n",m,n);}void prog5_1(){int i=5,j=6,k;printf("i=%d,j=%d\n",i,j);i++;++j;printf("[i++;++j]:i=%d,j=%d\n",i,j);i--;--j;printf("[i--;--j]:i=%d,j=%d\n",i,j);k=(i++)+(++j);printf("[k=(i++)+(++j)]:i=%d,j=%d,k=%d\n",i,j,k);k=(i--)+(--k);printf("[k=(i--)+(--k)]:i=%d,j=%d,k=%d\n",i,j,k);i=j=k=7;printf("[=j=k=7;]:i=%d,j=%d,k=%d\n",i,j,k);k+=++i;printf("[k+=++i]:i=%d,j=%d,k=%d\n",i,j,k);k%=++i;printf("k%=++i]:i=%d,j=%d,k=%d\n",i,j,k);k*=j--;printf("[k*=j--]:i=%d,j=%d,k=%d\n",i,j,k);}void prog6_1(){int a=0x64;int *pa=&a;char ch='A';char *pch=&ch;printf("整形变量a的值为a=%d\n",a);printf("整形变量a的指针为&a=%p\n",&a);printf("指针变量pa的值为pa=%p\n",pa);printf("指针变量pa的指针为&pa=%p\n",&pa);printf("字符变量ch的值为ch=%d\n",ch);printf("字符变量ch的指针为&ch=%p\n",&ch);printf("指针变量pch的值为pch=%p\n",pch);printf("指针变量pch的指针为&pch=%p\n",&pch);}void prog6_2(){int a=3,b=4,sum=0;int *pa,*pb,*psum;char ch;char *pch=&ch;pa=&a;pb=&b;psum=&sum;printf("指针变量的值:pa=%x  pb=%x  psum=%x\n",pa,pb,psum);printf("目标变量的值:a=%d   b=%d  sum=%d\n",*pa,*pb,*psum);*psum=*pa+*pb;*pch='A';printf("运算结果:sum=%d ch=%c\n",*psum,ch);printf("整形指针的+运算:pa=%x  pa+1=%x\n",pa,pa+1);printf("字符型指针的+运算:pch=%x  pch+1=%x\n",pch,pch+1);}int main(){prog1_1();prog1_2();prog5_1();prog6_1();prog6_2();prog7_1();prog7_2(); return 0;}当完全执行程序是到了prog7-1时输入三个字符asd程序并没有按我想的收到,而且prog7_2根本就没让我输入数字。当注释掉其他子函数,只执行prog7-1,prog7_2时就成功了。想请教一下这是为什么,如何改进。
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 1673 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信