Skip to content

Instantly share code, notes, and snippets.

@mertsimsek
Created March 16, 2013 12:42
Show Gist options
  • Save mertsimsek/5176217 to your computer and use it in GitHub Desktop.
Save mertsimsek/5176217 to your computer and use it in GitHub Desktop.
Read and Write on File in C
void readInput(char* inputFile) {
FILE *fp;
fp = fopen(inputFile, "r");
int x;
while ((x = fgetc(fp)) != EOF) {
printf("%c", x);
}
fclose(fp);
}
void writeOutput(char* outputFile, char* text) {
FILE *p = NULL;
size_t len = 0;
p = fopen(outputFile, "w");
if (p == NULL ) {
printf("Error in opening a file..");
}
len = strlen(text);
fwrite(text, len, 1, p);
fclose(p);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment