注册 登录
编程论坛 C++教室

找不出错误...望解答...

紫苏子 发布于 2007-07-16 03:14, 421 次点击
#include<stdio.h>
#include<stdlib.h>
#define BUFFERSIZE 1024
int main()
{
unsigned int a,b,sum;
char buffer[BUFFERSIZE];
printf("*************************************\n");
printf("* Welcome to use our counter *\n");
printf("* Input two integers in on line *\n");
printf("* The sum will be printe *\n");
printf("* Input the char '#' to quit *\n");
printf("*************************************\n");
while(fgets(buffer,BUFFERSIZE,stdin)!=NULL)&&(buffer[0]!='#');
{
if(sscanf(buffer,"%d%d",&a,&b)!=2)
{
printf("the input is skipped:%s",buffer);
continue;
}
sum=a+b;
printf("The sum of%dand%dis%d\n",a,b,sum);
}
return 0;
}


望高手指点...运行不了哦...
2 回复
#2
开心石2007-07-16 09:56
#include<stdio.h>
#include<stdlib.h>
#define BUFFERSIZE 1024
int main()
{
unsigned int a,b,sum;
char buffer[BUFFERSIZE];
printf("*************************************\n");
printf("* Welcome to use our counter *\n");
printf("* Input two integers in on line *\n");
printf("* The sum will be printe *\n");
printf("* Input the char '#' to quit *\n");
printf("*************************************\n");
while(fgets(buffer,BUFFERSIZE,stdin)!=NULL)&&(buffer[0]!='#'); /* while(A),表达试A要用括号 */
{
if(sscanf(buffer,"%d%d",&a,&b)!=2)
{
printf("the input is skipped:%s",buffer);
continue; /* continue 只用与循环语句中,用来退出本次循环,不能用在if句中 */
}
sum=a+b;
printf("The sum of%dand%dis%d\n",a,b,sum);
}
return 0;
}






改成下面样子:
#include<stdio.h>
#include<stdlib.h>
#define BUFFERSIZE 1024
int main()
{
unsigned int a,b,sum;
char buffer[BUFFERSIZE];
printf("*************************************\n");
printf("* Welcome to use our counter *\n");
printf("* Input two integers in on line *\n");
printf("* The sum will be printe *\n");
printf("* Input the char '#' to quit *\n");
printf("*************************************\n");
while((fgets(buffer,BUFFERSIZE,stdin)!=NULL)&&(buffer[0]!='#'));
{
if(sscanf(buffer,"%d%d",&a,&b)!=2)
{
printf("the input is skipped:%s",buffer);
goto loop;
}
sum=a+b;
printf("The sum of%dand%dis%d\n",a,b,sum);
loop:;
}
return 0;
}

[此贴子已经被作者于2007-7-16 9:57:33编辑过]

#3
紫苏子2007-07-17 03:22
谢谢~呵呵~~~~

[此贴子已经被作者于2007-7-17 3:30:43编辑过]

1