This is a C Program which creates a new file and writes some data into it.
We will use a file pointer to create a new file in write mode then we enter some data into it.
Then we read that data until end of file is reached and place that data in the file we just created.
PROGRAM :
OUTPUT :
Now open sample.txt file in the directory where you saved the c source file
We will use a file pointer to create a new file in write mode then we enter some data into it.
Then we read that data until end of file is reached and place that data in the file we just created.
PROGRAM :
#include <stdio.h> #include <stdlib.h> int main() { FILE *fp; char ch; fp = fopen("sample.txt","w"); printf("Write some text here !\n"); while((ch=getchar())!=EOF) putc(ch,fp); fclose(fp); return 0; }
OUTPUT :
Now open sample.txt file in the directory where you saved the c source file
No comments:
Post a Comment