Help with reading a string file into a 2d array
cant get it to print an external file
i have a file called months.dat
with all the months in the file...
Code:
#include<stdio.h>
#include<string.h>
#define MAX_LEN 100
int main(void)
{
int i;
char filename[MAX_LEN];
char words[12][MAX_LEN];
printf("Give the file you want to open: ");
scanf("%s",filename);
FILE *inp=fopen("months.dat","r"); //open file for reading
if(inp==NULL)
printf("File does not exist"); //prints error message
else
{
while(fscanf(inp,"%s",words[i])!=EOF) //scan for a word
{ // i++; //increase letter by one
printf("%s",words[i-1]);
i++;
}
}
fclose(inp);
return(0);
}