你好,我想用 C 语言比较不同字符串的两个字符,但它不起作用,请帮助我:
int main (void)
{
string b="blue";
int len=strlen(b);
int numbers[]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25};
string letters="abcdefghijklmnopqrstuvwxyz";
int leng=strlen(letters);
int key [len];
for (int i=0; i<len;i++)
{
for (int j=0; j<leng;j++)
{
if (&b[i]==&letters[j])
{
//The program never comes inside here
key[i]=numbers[j];
}
}
}
//The result should be key[]={1,11,20,4 }
}
最佳答案
使用:
b[i]==letters[j]
代替
&b[i]== &letters[j]
后者比较指针值。
关于比较C中不同字符串的两个字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21563378/