I need to read from an input file by using C programming language to do one of my assignments.
Here's my code:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
char *input = readFromFile(argv);
return 0;
}
char *readFromFile(char *argv[])
{
FILE *fp;
fp = fopen(argv[1],"r");
char *input, c;
int i = 0;
while(!feof(fp))
{
c = fgetc(fp);
input[i++] = c;
}
fclose(fp);
return input;
}
I want to do this reading operation in another function, not in function main()
. I tried, but couldn't do it.
When I try to do it with the code above, I get an error message that says:
conflicting types for
readFromFile()
How can I fix this error and do what I want?