Header file:
stdio.h
Synopsis:
int fputc(int c, FILE *stream);
Description:
It writes the character 'c' on the given stream. Returns the written character on success. Otherwise, EOF is returned.
fputc function C example:
#include<stdio.h>
int main() {
char ch;
FILE *fp;
fp = fopen("file.txt", "w");
while ((ch = getchar()) != EOF)
fputc(ch, fp);
return 0;
}
int main() {
char ch;
FILE *fp;
fp = fopen("file.txt", "w");
while ((ch = getchar()) != EOF)
fputc(ch, fp);
return 0;
}
Output:
jp@jp-VirtualBox:~/cpgms/exp$ ./a.out
Hello world
jp@jp-VirtualBox:~/cpgms/exp$ cat file.txt
Hello world
Hello world
jp@jp-VirtualBox:~/cpgms/exp$ cat file.txt
Hello world
No comments:
Post a Comment