So I have to make a maze program, and to start I must scan in the maze to a 2d array. The problem arises when i go to put the chars into the array, when the enter char and the space char always take up the first slot in the array...
Here is my code:
int main(){
int row, col;
int i,j,k,l;
scanf("%d", &row);
scanf("%d", &col);
char** maze = (char**) calloc(row, sizeof(char*));
for ( k = 0; k < row; k++ )
{
maze[k] = (char*) calloc(col, sizeof(char));
}
for(i=0;i<row;i++){
for(j=0;j<col;j++){
scanf("%c",&maze[j][i]);
}
}
for(k=0;k<row;k++){
for(l=0;l<col;l++){
printf("%c", maze[k][l]);
}
printf("\n");
}
return 0;
}
And the output is:
With the enter char:
3
3
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xx
xxx
xxx
With a space:
3
3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xx
xxx
xxx
without any thing: (this one works)
3
3xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxx
xxx
xxx