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的意义主要是判断两个字符串是否相同

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。