Skip to content

Instantly share code, notes, and snippets.

@enile8
Created January 8, 2013 03:23
Show Gist options
  • Select an option

  • Save enile8/4480917 to your computer and use it in GitHub Desktop.

Select an option

Save enile8/4480917 to your computer and use it in GitHub Desktop.
Writing to file with C
#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