Created
January 8, 2013 03:23
-
-
Save enile8/4480917 to your computer and use it in GitHub Desktop.
Writing to file with C
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> | |
| int main() | |
| { | |
| char str [256]; | |
| puts("Enter some text you would like to add to the file:"); | |
| fgets(str,255,stdin); | |
| FILE * pFile; | |
| pFile = fopen("myfile.txt", "a"); | |
| if (pFile==NULL) | |
| { | |
| pFile = fopen("myfile.txt", "w"); | |
| } | |
| else if (pFile!=NULL) | |
| { | |
| fputs(str,pFile); | |
| fclose(pFile); | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment