注册 登录
编程论坛 C++教室

[求助]关于字符串的比较问题

song_gpqg 发布于 2007-03-16 20:07, 584 次点击

遇到的题目要判断一个字符的二维数组a[][]是不是‘0’
我用的是strcmp(a[i],'0')!=0
可是会报错,
error C2664: 'strcmp' : cannot convert parameter 2 from 'const char' to 'const char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast

不知道为什么?要怎么改?希望大虾指点一下 谢谢!

6 回复
#2
wfpb2007-03-16 20:23
if(a[i][j]!='0')//a[i]是char*类型,'0'是char型,类型不匹配....
#3
song_gpqg2007-03-16 21:07
哦哦 谢谢这个明白了
但是那个是我程序的一部分

for(m=0;m<100;m++)
for(j=0;j<102;j++) a[m][j]='0';
do
{
scanf("%s" ,a[i]);
i++;
}while(strcmp(a[i],'0')!=0);

在while 里面的不知道怎么改呢?
是读入字符串 如果是0就停止
#4
litcatyx2007-03-16 21:50
while(strcmp(a[i],“0”)!=0;
#5
song_gpqg2007-03-16 21:59
还是不能通过。。。555555555555555
#6
litcatyx2007-03-16 22:12
int main()
{
char a[100][102];
for(int m=0;m<100;m++)
for(int j=0;j<102;j++) a[m][j]='0';

int i=0;
do
{
scanf("%s" ,a[i]);
}while(strcmp(a[i++],"0")!=0);

}
#7
song_gpqg2007-03-16 22:36

感谢LITCAYYX!把I++改成I-1就对了!
呵呵 谢啦~

1