I’m still pretty new to C. I still don’t understand everything with pointers at all.
I’m trying to make a method that returns a String.
Here’s the function, it’s still incomplete.
char getS(char *fileName){
FILE *src;
if((src = fopen(fileName, "r")) == NULL){
printf("%s %s %s", "Cannot open file ", fileName, ". The program is now ending.");
exit(-1);
}
char *get = " ";
//insert getting a random word here
return(*get);
}
and I’m trying to call the method like this
char *article = getS("articles.txt");
char *noun = getS("nouns.txt");
char *verb = getS("verbs.txt");
The compiler is giving me this:
error: invalid type argument of unary ‘*’ (have ‘int’)
What should I do?
Your function should return a char * (a string), instead of a char, and it should return the same. So the function becomes: