我是C语言的初学者,我正在编写一个程序来查找字符串中字符的频率。我在这里遇到了访问冲突,但我无法解决它。在while循环中,我要循环得到字符串数组中的每个唯一字符,并将其存储在另一个数组中。能帮我个忙吗?提前谢谢。
int main()
{
char str[5][10];
int i=0, j=0, k, l=0;
char chh[10];
strcpy(chh, "a"); while (l < 5)
{
if (strcmp(chh[i],str[l][j]) != 0) <--- access violation in this line.
{
chh[i] == str[l][j];
i++;
}
if (j >= 9)
j = 0;
l++;
j++;
}
}发布于 2014-03-02 18:52:58
您正在使用strcmp来比较两个字符。
http://www.cplusplus.com/reference/cstring/strcmp/
int strcmp ( const char * str1, const char * str2 );您应该删除该strcmp并直接比较这两个字符。
chh[i] == str[l][j]编辑的
你可能想
if (j >= 9){
j = 0;
l++;
}https://stackoverflow.com/questions/22131770
复制相似问题