Hey i am trying to make a function to open the file but am having trouble. The original code looks lie:
Code:
fp=fopen(argv[1], "r");
if(text==NULL) {
EMPTY_FILE(1);
}
else {
while((fgets(text[i], SIZE, fp)!=NULL)) {
i++;
}
And this was my attempt to turn it into a function including the prototype and the function after the main:
Code:
int READ_FILE(char filename[], char text[][SIZE+1]);//prototype
READ_FILE(argv[1], text);//this part is in the main code
//And this part is after the main
int READ_FILE(char filename[], char text[][SIZE+1]){
int i=0;
FILE * fp;
fp=fopen(filename, "r");
if(text==NULL) {
EMPTY_FILE(1);
}
else {
while((fgets(text[i], SIZE, fp)!=NULL)) {
i++;
}
return i;
}
}
I know this code doesn't work because it doesn't compile and i don't know why
I am fairly new to making functions and implementing them.
Any help is greatly appreciated