Hi, im currently writing a wordsearch programme and am on to the part where i need to store the information from a file into a 2D array.
This is the content of the file that i am using:
25 15
xmfycxvtljlqbbybkoumjqwbt
baubmeknbeydqmcnzyjpvrack
qqactivexnyvwdvcoshoyathg
vaghzkctudptjdphsztprbttl
obsnakjwqbouftmgnjqbylinu
vsewohvobxsduqjiffkoylodo
dukwwefroyamapmlrrjvdolop
iqkfxtlksjufmtrsbycmqrrri
afervlqidqxxaoanfqjlmcpjh
yoyywrbpfcalflcbbcoecspwl
twbxetyuyufvvmcuawjmbwlqh
txokdexmdbtgvhpyvsqtmljdx
dcatenrehteoxqdgnueljtrrn
jarteqvtxejfsqddkbuhcysfq
hpdrowssapxtrxhpdxcdhicon
i have already set up the C programme so that it opens the file and then reads the first line of the file so it knows what the height and width of the grid will be.
However im having trouble trying to work out how to put it into an array.
I will post my code below, but i would just like to let you know that i am yet to get something 100% solid so what you will see in my programme getting the content into the array is most probably a lot of bulls***
To put it plainly - Im having trouble taking this:
xmfycxvtljlqbbybkoumjqwbt
baubmeknbeydqmcnzyjpvrack
qqactivexnyvwdvcoshoyathg
vaghzkctudptjdphsztprbttl
obsnakjwqbouftmgnjqbylinu
vsewohvobxsduqjiffkoylodo
dukwwefroyamapmlrrjvdolop
iqkfxtlksjufmtrsbycmqrrri
afervlqidqxxaoanfqjlmcpjh
yoyywrbpfcalflcbbcoecspwl
twbxetyuyufvvmcuawjmbwlqh
txokdexmdbtgvhpyvsqtmljdx
dcatenrehteoxqdgnueljtrrn
jarteqvtxejfsqddkbuhcysfq
hpdrowssapxtrxhpdxcdhicon
and storing it in an array, because its in a file
Code:
#include <stdio.h>
int main(void)
{
char filename[25];
char wordsearch[i] [j];
int height, width ;
FILE *f;
/* start of code for opening file */
{
printf("Please specify input file\n");
scanf("%s", filename);
f = fopen(filename, "r");
while (f==NULL)
{
printf("Couldn't open input file, please change the file name \n");
scanf("%s", filename);
f = fopen(filename, "r");
}
} /* end of code for opening file */
{
fscanf(f,"%d %d", &height, &width);
printf("The height of the grid is... %d\n", height);
printf("The width of the grid is... %d\n", width);
}
{
/* start of code to putting content of file into array
int column;
int row;
for (column = 0, column < height, i++)
fscanf(f, "%s\n", &wordsearch[i]);
for(row = 0, row < width, i++)
fscanf(f, "%s\n", &wordsearch[i]);
*/
}
}
any input will be greatly apprectiated.