jiuqing_911 2019-12-09 21:57 采纳率: 0%
浏览 219

统计句子中的字母和字符,为什么会报错

#统计三段80个字符的短句数字,字母,字符的个数

#include
#include
using namespace std;
int main()
{
char wz[3][80];
int i,j,daxie=0,xiaoxie=0,shuzi=0,kongge=0,zifu=0,fuhao=0;
for (i=0;i for (j=0;i cin >> wz[i][j];
for (i=0;i for (j=0;i {
if ((strcmp(wz[i][j],'A')>=0) && (strcmp(wz[i][j],'Z')<=0)
daxie = 1+daxie;
if ((strcmp(wz[i][j],' ')=0)
kongge = 1+kongge;
if ((strcmp(wz[i][j],'a')>=0) && (strcmp(wz[i][j],'z')<=0)
xiaoxie = 1+xiaoxie;
if ((strcmp(wz[i][j],'1')>=0) && (strcmp(wz[i][j],'9')<=0)
shuzi = 1+shuzi;
else
fuhao = 1+fuhao;
}
cout<<"shuzi"<<shuzi<<endl<<"zifu"<<zifu;
cout<<"daxie"<<daxie<<endl<<"xiaoxie"<<xiaoxie;
cout<<"kongge"<<kongge;
return 0;

报错提示

Compiling...
统计字符.cpp
C:\Users\24636\Desktop\vc\统计字符.cpp(14) : error C2664: 'strcmp' : cannot convert parameter 1 from 'char' to 'const char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
C:\Users\24636\Desktop\vc\统计字符.cpp(14) : error C2664: 'strcmp' : cannot convert parameter 1 from 'char' to 'const char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
C:\Users\24636\Desktop\vc\统计字符.cpp(15) : error C2146: syntax error : missing ')' before identifier 'daxie'
C:\Users\24636\Desktop\vc\统计字符.cpp(16) : error C2664: 'strcmp' : cannot convert parameter 1 from 'char' to 'const char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
C:\Users\24636\Desktop\vc\统计字符.cpp(17) : error C2146: syntax error : missing ')' before identifier 'kongge'
C:\Users\24636\Desktop\vc\统计字符.cpp(18) : error C2664: 'strcmp' : cannot convert parameter 1 from 'char' to 'const char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
C:\Users\24636\Desktop\vc\统计字符.cpp(18) : error C2664: 'strcmp' : cannot convert parameter 1 from 'char' to 'const char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
C:\Users\24636\Desktop\vc\统计字符.cpp(19) : error C2146: syntax error : missing ')' before identifier 'xiaoxie'
C:\Users\24636\Desktop\vc\统计字符.cpp(20) : error C2664: 'strcmp' : cannot convert parameter 1 from 'char' to 'const char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
C:\Users\24636\Desktop\vc\统计字符.cpp(20) : error C2664: 'strcmp' : cannot convert parameter 1 from 'char' to 'const char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
C:\Users\24636\Desktop\vc\统计字符.cpp(21) : error C2146: syntax error : missing ')' before identifier 'shuzi'
执行 cl.exe 时出错.

统计字符.obj - 1 error(s), 0 warning(s)

  • 写回答

1条回答

  • cyzzing 2019-12-09 22:28
    关注

    strcmp函数的参数是指针 而你传递的是数值

    既然是处理字符 为什么要用函数strcmp呢 直接比较大小不就可以了吗?

    比如if ((strcmp(wz[i][j],'A')>=0) && (strcmp(wz[i][j],'Z')<=0)
    应该写成: if (wz[i][j] >= 'A' && wz[i][j]<='Z') 就可以了

    strcmp的意义主要是判断两个字符串是否相同

    评论

报告相同问题?

悬赏问题

  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样