Search code examples
ccompiler-errorsideoutputascii

C I am Getting Wrong Output


I have a C code, When I run the code, different symbols appear where there should be underscores.

int main(void){
    char matrix[32][63];
    int i,j;
    for(i=0;j<32;i++){
        for(j=0;j<63;j++){
            matrix[i][j]='_';
        }
    }
    int n;
    printf("Enter number of iteration: ");
    scanf("%d",&n);
    fillOnes(matrix,0,31,32,n);
    for(i=0;i<32;i++){
        for(j=0;j<63;j++){
            printf("%c",matrix[i][j]);
        }
        printf("\n");
    }
    return 0;
}

why am i getting output like this instead of underscore and how can i fix it.

enter image description here


Solution

  • As explained in the comments by @Sedenion

    Your loop intializing your matrix has an error.

    int i,j;
    for(i=0;j<32;i++)
    {
        for(j=0;j<63;j++)
        {
            matrix[i][j]='_';
        }
    }
    

    Do you see anything wrong here? :)