Hi all, I am a beginner to C. The following is not a completed program, or even a part of a program, but I see no point in writing any more before I can get this to compile...
Code:
#include <stdio.h>
#include <stdlib.h>
int get_filename();
int main(void){
//declarations
FILE *input_stream;
//program statements
input_stream = fopen( get_filename(), "r" ) ); //line 37
//there will be error checking here, in the form of an if, eventually
}
int get_filename(){
//declarations
char filename[101];
//program statements
printf("enter filename: ");
scanf( "%s", filename);
return (filename); //line 47
}
The problem is already obvious to you guys, but I am getting the following errors:
37 passing arg 1 of `fopen' from incompatible pointer type
37 syntax error before ')' token
In function `get_filename':
47 [Warning] return makes integer from pointer without a cast
47 [Warning] function returns address of local variable
To me this appears to be basically one error, that manifests in several places. I think it is to do with the returning of the contents of the variable filename. Of course, I could just put it in main, but that would be like giving up, and I will need to know how to do this in the future, anyway. Can you return strings out of functions like that? I have tried the FAQ and everything, to no avail....any ideas?
Thanks in advance...
fraktal