Please help. I learning about function with return pointer value.
The function is supposed to return value from the file in my main, but I am getting empty value.
I am trying to get better with pointer. Right now just teaching myself. Please help.
right now the only way for this code to show value is when in put the putchar(*ps) inside my readfile function. I would like to readfile to return value and print in the main function.
Thanks again everyone..for reading.and helping out.
Code:
#include <stdio.h>
char *readfile(char filename[]);
int main(int argc, char *argv[] ) {
char output[400];
char *pout;
pout = output;
pout = readfile(argv[1]);
printf("%c\n", *pout++);
}
//this is the function that takes file name.... and return pointers.
char *readfile(char filename[] ) {
char c;
char string[400];
char *ps;
ps = string;
FILE *myfile;
int x;
myfile = fopen(filename, "r");
while ((c=fgetc(myfile)) != EOF){
*ps = c;
x++;
}
return ps;
}