C++改错题,继续救命

来源:百度知道 编辑:UC知道 时间:2024/07/12 20:53:09
#include<iostream.h>
void count(char,int&,int&,int&,int&)
void main(viod)
{
int caps=0,space=0,num=0,other=0;
char str[80];
cout<<"Input a string:";
cin>>str;
cout<<str<<endl;
count(str,caps,space,num,other);
cout<<"\nString:"<<str<<endl;
cout<<"Caps:"<<caps<<endl;
cout<<"Space:"<<space<<endl;
cout<<"Num:"<<num<<endl;
cout<<"Other:"<<other<<endl;
}
void count(char p[],int&caps1,int&space1,int&num1,int&other1)
{
for(int i=0;p[i]=="\0";i++)
{
if (('A'<=p[i]&&(p[i]<='Z'))
++caps1;
else if((p[i]<='9')&&(p[i]>='0'))
++num1;
else if(p[i]='')
++space1;
else ++other1;
}
}

void count(char,int&,int&,int&,int&) 后面少个;
void main(viod) viod是啥呵呵
void count(char,int&,int&,int&,int&)声明与实现的第一个参数类型不同,声明中是char,实现中是char *
for(int i=0;p[i]=="\0";i++) 中"\0"改为'\0'
if (('A'<=p[i]&&(p[i]<='Z')) 中括号发生错误
else if(p[i]='')中''中应加上一空格或者改为0x20
以上是编译出错
算法:
cin>>str; cin是输入直到空格,所以一旦字符串中有空格则停止,比如输入
abc ef,str中内容只有abc
可用cin.getline(str, 80, '\n');代替。

for(int i=0;p[i]=="\0";i++) 改为for(int i=0;p[i] != '\0';i++)
else if(p[i]=0x20)改为else if(p[i]==0x20)

else if(p[i]=' ')
两个引号之间要有空格!!!