I'm trying to scan a line from a open file pointer, the one passed to the function is stdin. When I print out the value of input I get (null). Any ideas why fscanf is not saving the value? This is the code — also shown below:
char *ReadLineFile(FILE *infile){
char *input;
char buf[MAX];
//check if file pointer is at end of file
if(feof(infile))
return NULL;
//scan from file
fscanf(infile,"%s",input);
printf("%s",input);
input = (char *)malloc(strlen(input)+1);
//handle memory allocation errors
if (input == NULL){
printf("Error allocating memory\n");
return "error";
}
fclose(infile);
return input;
}