Write a C program for File Operations to read a string of characters from standard input and prints the entered string of charatcters using fgetc() and fputc() function. fgetc() is used to obtain input from a file single character at a time. fputc() is used to write a single character at a time to a given file.
Input : good bye
Output : good bye
#include <stdio.h>
int main() {
int buf[1024];
int i, n;
for (i=0; i<1024; i++) {
int ch;
ch = fgetc(stdin);
if (ch == EOF) {
n = i+1;
break;
}
buf[i] = ch;
}
fputc('\n', stdout);
for (i=0; i<n; i++) {
fputc(buf[i], stdout);
}
fputc('\n', stdout);
return 0;
}
Comments
Leave a comment