急!关于C++编程的问题

来源:百度知道 编辑:UC知道 时间:2024/06/14 07:28:30
#include<stdio.h>
#define LSIZE 81
#define YES 1
#define NO 0
int main()
{
int countlines(char[],int);

char message[LSIZE],y;
char c;
int i,num;

printf("Please enter sentence\n");
printf("And when you want to stop,please enter '0'!:\n");
i=0;
while(i<(LSIZE-1)&&(c=getchar())!='0')
{
message[i]=c;
i++;
}
message[i]='\0';

num=countlines(message,i);
printf("%d lines",num);

return 0;
}

int countlines(char list[],int i)
{
int inlines,count=0;

inlines=NO;
for(i=0;list[i]!='0';i++)
{
if(list[i]=='\n')
inlines=NO;
else if(inlines==NO)
{
inlines=YES;
count++;
}
}

return(count);
}

检查后并没有任何错误
但是运行后

for(i=0;list[i]!='0';i++)
'0'改成'\0'

我发现主函数main()当中的变量 char message[LSIZE],y;
这里的y是不是多余的,
去掉就能运行了。

是你的电脑出现问题呀!重新装一台试试就可以了!你的电脑主板是二手的哟