Skip to content

Commit

Permalink
Add fwrite program
Browse files Browse the repository at this point in the history
Signed-off-by: Prashant Shah <[email protected]>
  • Loading branch information
prashants committed Oct 10, 2012
1 parent 5ba69c3 commit 06b803b
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions fwrite/fwrite.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* fwrite - Write to a file
*
* Written in 2012 by Prashant P Shah <[email protected]>
*
* To the extent possible under law, the author(s) have dedicated
* all copyright and related and neighboring rights to this software
* to the public domain worldwide. This software is distributed
* without any warranty.
*
* You should have received a copy of the CC0 Public Domain Dedication
* along with this software.
* If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
*/

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
FILE *f;
char str[] = "Hello World";

f = fopen("./test.txt", "w");
if (!f) {
perror("Error opening file");
exit(1);
}

/* reduce size of str by 1 to remove \0 */
fwrite(str, sizeof(str) - 1, 1, f);

fclose(f);
return 0;
}

0 comments on commit 06b803b

Please sign in to comment.