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 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路