ok I'm taking a text file.. 16 lines.. 6 character values per line and trying to randomly get one character per each line.. and place them into a 2d array (4x4). The values i'm getting aren't correct for some reason.. anyone have any helpful tips?
int main()
{
srand (time(NULL));
int r;
char line[6];
char board[4][4];
char c;
FILE *fid;
fid = fopen("file.txt","r");
int i=0; int j=0;
while (fgets(line, sizeof(line), fid)!=NULL)
{
fscanf(fid, "%s", &line);
r = rand()%5;
printf("The random number is: %d\n", r);
printf("The line is %s\n", line);
c = line[r];
board[i][j]=c;
if (i==3)
{
i=0;
j++;
}
else
{
i++;
}
}
for(i=0; i<4; i++)
{
for(j=0; j<4; j++)
{
printf("%c\n",board[i][j]);
}
}
return 0;
}