I having trouble with a programme im trying to write
I have it so it asks for a file name, opens that file if it exists or comes up with error message if it doesnt.
But what im stuck on it how would i get the content of that file put in to an array or into variables
for example in the file on the first line it says:
25 15
this is the hight of a grid, now i want these to be put into varabiels that are called Height and width, but i am at the moment finding it hard to do so.
This is the code i have so far
Any help will be greatly appreciated.Code:#include <stdio.h> int main(void) { char filename[25]; char wordsearch[50] [50]; char height[50]; int width[50]; FILE *f; { /* Code for opening the 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("%s", height); printf("The height of the grid is... ", height); } }



LinkBack URL
About LinkBacks


