So the plan is to create a wordsearch by reading in characters from a file into an array. This is my code so far, nowhere near finished but have encountered a problem already:
-----------------------------
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ROWS 20
#define COLUMNS 20
int main()
{
FILE *myfile;
char wordsearch[ROWS][COLUMNS];
char c;
int x,y;
myfile = fopen("words.txt","r");
if (myfile == NULL)
{
printf("Could Not Open File\n");
}
else {
printf("WORDSEARCH\n");
}
printf("\n");
x=0;
y=0;
c=getc(myfile);
while (c != EOF){
if (c != ' '){
wordsearch[y][x] = c;
x++;
if (y>=20){
x=0;
y++;
}
}
}
for (y=0;y<COLUMNS;y++){
for (x=0;x<ROWS;x++){
printf("%c",wordsearch[y][x]);
}
}
return 0;
}
--------------------------
My question is to do with the section highlighted in red... I can't really see why it is not printing out my array (wordsearch), it's probably very basic but I have no C experience so am not too confident in what I'm doing. Any help with this bit would be much appreciated the rest I can work on afterwards.