c++编写一个 函数,统计一条英文句子中字母的个数,在主程序中实现输入、输出。
我编的程序是这样的:#include<iostream.h>#include<string.h>intcount(chara[]);intmain(){intd;char...
我编的程序是这样的:
#include<iostream.h>
#include<string.h>
int count(char a[]);
int main()
{
int d;
char c[];
char b;
cin>>b;
strcpy(c,b);
d=count(c);
cout<<d;
return 0;
}
int count(char a[])
{
int b=0,c=0;
do
{
if((a[c]>'a'&&*a[c]<'z')||(a[c]>'A'&&*a[c]<'Z'))
b++;
c++;
}while(a[c]!='\0');
return b;
}
编译时出现了错误:
C:\VC6\MyProjects\shiyan5dian6\进阶3.cpp(7) : error C2133: 'c' : unknown size
C:\VC6\MyProjects\shiyan5dian6\进阶3.cpp(10) : error C2664: 'strcpy' : cannot convert parameter 2 from 'char' to 'const char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
C:\VC6\MyProjects\shiyan5dian6\进阶3.cpp(20) : error C2100: illegal indirection
C:\VC6\MyProjects\shiyan5dian6\进阶3.cpp(20) : error C2100: illegal indirection
执行 cl.exe 时出错.
shiyan5dian6.exe - 1 error(s), 0 warning(s)
怎么在现有基础上改正? 展开
#include<iostream.h>
#include<string.h>
int count(char a[]);
int main()
{
int d;
char c[];
char b;
cin>>b;
strcpy(c,b);
d=count(c);
cout<<d;
return 0;
}
int count(char a[])
{
int b=0,c=0;
do
{
if((a[c]>'a'&&*a[c]<'z')||(a[c]>'A'&&*a[c]<'Z'))
b++;
c++;
}while(a[c]!='\0');
return b;
}
编译时出现了错误:
C:\VC6\MyProjects\shiyan5dian6\进阶3.cpp(7) : error C2133: 'c' : unknown size
C:\VC6\MyProjects\shiyan5dian6\进阶3.cpp(10) : error C2664: 'strcpy' : cannot convert parameter 2 from 'char' to 'const char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
C:\VC6\MyProjects\shiyan5dian6\进阶3.cpp(20) : error C2100: illegal indirection
C:\VC6\MyProjects\shiyan5dian6\进阶3.cpp(20) : error C2100: illegal indirection
执行 cl.exe 时出错.
shiyan5dian6.exe - 1 error(s), 0 warning(s)
怎么在现有基础上改正? 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询