This is the code:
#include <stdio.h>
#include <stdlib.h>
void acceptMaze(char maze[ROW][COLOUMN], int nrows, int ncols)
{
int i,j;
for (i = 0; i < nrows; i++)
{
fprintf(stdout,"I = %d",i);
for (j = 0; j < ncols; j++)
{
fprintf(stdout,"J = %d",j);
scanf("%c",&maze[i][j]);
}
}
}
wel while entering data it saysi =0 j=0j=1 .So you see the j=0 doesn’t remains.I am using a linux system .Can anyone fix this.
Your problem stems from the fact that the
%cconversion specifier doesn’t skip whitespace. If there’s a newline stuck in the input stream from a previous input operation, thescanfcall will read that and assign it tomaze[i][j].Here’s one workaround:
The line
do c = getchar(); while (isspace(c))will read input characters until you hit a non-whitespace character.EDIT
Ugh, I just realized one ugly flaw of this scheme; if you want to a assign a whitespace character like a blank to your maze, this won’t work as written. Of course, you can just add to the condition expression: