Displaying this symbol ╠ instead of desired characters

≡放荡痞女 提交于 2019-12-12 02:35:59

问题


Here is a snippet of some code. Instead of displaying the characters I am checking for, ╠ is displayed.

while (c!= EOF)
{
    c = getc(fp);
    if (c==32 || c==33 || (c>=97 && c<=122) || c==35)
    j++;
    if(j==clns){
    i++;
    j=0;
    mA[i][j]=c;
    }

}


for (i = 0; i < 10; i++) {
    for (j = 0; j < 20; j++) {
        printf("%c", mA[i][j]);
    }
    printf("%c\n", mA[i][j]);
}

Thanks in advance for your help. :)


回答1:


You are only ever writing to mA[i][0]:

if(j==clns){
    i++;
    j=0;
    mA[i][j]=c;
}

so you are printing random garbage that happened to be in the array. Move the assignment out of the if.



来源:https://stackoverflow.com/questions/12905027/displaying-this-symbol-instead-of-desired-characters

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!