-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Prashant Shah <[email protected]>
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
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; | ||
} | ||
|