I'm new to C and getting confused with the pointers and char arrays...
I have this written:
char *read(char *filename) {
char *text[1000];
FILE *inputFile = fopen(filename, "r");
int i=0;
while (feof(inputFile)) {
text[i++] = fgetc(inputFile);
}
text[i]='\0';
fclose(inputFile);
return text;
}
My goal is to pass in the name of the file that I want to open, open it, and assign all of the words in it into a char array (char text[]
). I continually get errors regarding:
expression which evaluates to zero treated as a null pointer constant of type 'char *' [-Wnon-literal-null-conversion]
incompatible pointer types returning 'char *[1000]' from a function with result type 'char *' [-Wincompatible-pointer-types]
Looking for any advice.