I just can't figure out where this error is coming from. I get a segment violation each time. Does anyone have any ideas. This is my first attempt at working with files, so any help would be nice. Thank you
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void filename_accept(char fileName[]);
int main()
{
FILE *myfile;
char fileName[40];
char fileData[1000];
int c;
filename_accept(fileName);
myfile = fopen(fileName,"r");
while((c = fgetc(myfile)) != EOF)
{
int i=0;
fileData[i++] = c;
}
fclose(myfile);
free(fileData);
return 0;
}
void filename_accept(char fileName[]) /*Reads in file name*/
{
printf("\nEnter file you would like to open:\n");
gets(fileName);
}