优美的英文爱情句子:C程序出了点问题,帮者重谢

来源:百度文库 编辑:中科新闻网 时间:2024/04/29 17:11:10
下面的程序是模拟手机拨号的,我用的是if --else if----else 来控制,当输入的为110,10000等不到11位的特殊号码用IF控制,当输入的为11位手机号,用ELSE IF控制.否则提示错
main()
{
int a[11],i;
char num;
printf("input your num:");
scanf("%c",&num);
if (strlen(num)<11)
{
switch(num)
{
case '110': printf("your calling is 110,please waiting......"); break;
case '100001': printf("your calling is 100001,please waiting......"); break;
default: printf("your calling is wrong,please chack it ");
}
}

else if(strlen(num)==11)
{
for(i=0;i<11;i++)
{
a[i]=a[i]-'0';
if (a[i]<0&&a[i]>9)
{
continue;
}
else
{
scanf("%d",&a[i]);
printf("your calling is %d,please waiting.....",a[i]);
}
}
}

else
{
printf("your calling is wrong ,please check it!" );
}

getch();
}

你写的是接收单字符 是不可以接收字符串的
还有switch只能判断单字符或者数字,不能判断字符串
所以你的程序根本不可能出结果

#include<stdio.h>
#include<string.h>
void main()
{
int a[11],i;
double num;
printf("input your num:");
scanf("%d",&num);
if (num<10000000000)
{
switch(int(num))
{
case 110: printf("your calling is 110,please waiting......"); break;
case 100001: printf("your calling is 100001,please waiting......"); break;
default: printf("your calling is wrong,please chack it ");
}
}

else if(num>=1000000000&&num<=99999999999)
{
for(i=0;i<11;i++)
{
a[i]=a[i]-'0';
if (a[i]<0&&a[i]>9)
{
continue;
}
else
{
scanf("%d",&a[i]);
printf("your calling is %d,please waiting.....",a[i]);
}
}
}

else
{
printf("your calling is wrong ,please check it!" );
}

}

你对C语言还不熟悉,要再看看书,希望你早日成为高手。
case '100001':这样的话应该是概念问题,不应该犯的错。
#include <string.h>
#include <conio.h>
void main()
{
char buf[100],ch,*temp;
int l=0;/*求电话号码长度*/
printf("input your num:");
temp=buf;
while(1) {
ch=getch();
/*如果输入的是0..9字符则回显,并把他们加入到缓冲区buf中,同时指针后移*/
if (ch>='0' && ch<='9') {*temp++=ch; putch(ch); l++; continue; }
if (ch=='\n') break; /*如果输入的是回车则输入过程结束*/
if (ch=='\r') break; /*如果输入的是换行则输入过程结束*/
if (ch=='\0') break; /*如果输入的是字符串结束符则输入过程结束*/
if (l>11) break; /*如果输入超过11个数字,则跳出输入过程*/
/*如果输入的是其他非法字符则忽略,循环*/
}
*temp='\0'; /*添加字符串结束符*/
if (0==strcmp("110",buf)) printf("your calling is 110,please waiting......");
else if (0==strcmp("100001",buf)) printf("your calling is 100001,please waiting......");
else if(l!=11) printf("your calling is wrong,please chack it ");
else printf("your calling is %s,please waiting.....",buf);
getch();
}

楼上说得很详细,小的就不敢在这里再胡闹了。呵呵。