我该如何修复这个功能?我得到的错误是:从char到char char*的无效转换
if(strcmp('\0', p->pubLow[i][j]) == 0) {
Run Code Online (Sandbox Code Playgroud)
码:
struct Prefix {
int no; // number of entries
int area[MAX]; // area elements
char pubLow[MAX][8]; // low end of publisher range
char pubHgh[MAX][8]; // high end of publisher range
int pubLen[MAX]; // no of chars in publisher string
};
int minNoDigits(const Prefix* p, int area) {
int minNoDigits = 0;
for(int i = 0; i < p->no; i++) {
if(area == p->area[i]) {
cout << "p->pubLow[i] is: " << p->pubLow[i] << endl;
minNoDigits = 1;
for(int j = 1; j < 3; j++) {
if(p->pubLow[i][j] = '\0') {
j = 3;
i = p->no;
}
else {
minNoDigits++;
}
}
}
}
return minNoDigits;
}
Run Code Online (Sandbox Code Playgroud)
编辑以提供更多信息.
我把线路改成了
if(p->pubLow[i][j] = '\0') {
Run Code Online (Sandbox Code Playgroud)
新错误:
assignment of read-only location p->Prefix::pubLow[i][j]
Run Code Online (Sandbox Code Playgroud)
我理解p->pubLow[i][j]其实是一个char,因为pubLow你的代码似乎是一个char**所以这就是你要找的东西:
if(p->pubLow[i][j] == '\0') {
Run Code Online (Sandbox Code Playgroud)
strcmp() 有以下原型:
int strcmp ( const char * str1, const char * str2 );
Run Code Online (Sandbox Code Playgroud)
这是文档.
因此,总而言之,您正在尝试比较2 个字符,strcmp()并且旨在比较2个常量字符串.
| 归档时间: |
|
| 查看次数: |
874 次 |
| 最近记录: |