Created
June 12, 2014 10:37
-
-
Save morganp/5aca106c74ae3f2f2ef8 to your computer and use it in GitHub Desktop.
Function returns File Pointer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
//static FILE *Sfile; | |
static int Sfile_open=0; | |
FILE *Open_Sfile(char *modname){ | |
char file_name[256]; | |
FILE *Sfile; | |
if (Sfile_open==0) { | |
strcpy(file_name,modname); | |
Sfile=fopen(file_name,"w"); | |
printf("// Writing file %s\n",file_name); | |
Sfile_open=1; | |
}; | |
return Sfile; | |
} | |
int main(int argc, char **argv) { | |
FILE *source_file; | |
source_file = Open_Sfile("example.txt"); | |
fprintf(source_file, "Helloworld\n"); | |
fclose(source_file); | |
exit(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment