In this tutorial we will learn how to create a file and write data in it....
EX: Write a C program to create a file and write data in it, How to write to a file in C. C program to write data into a file.
Program using fputs funtion:
#include<stdio.h>
void main()
{
FILE *fp;
fp = fopen("file.txt", "w");
fputs("Welcome to C file handling tutorials......", fp);
fclose(fp);
}
In above program we used fputs() to write data in a file, fputs() function is used to write string in file and if we use fputc() function then we can able to write only one character in file.
If we will open the file.txt file then we will see the following output:
- Above same program using fputc() function:
#include<stdio.h>
void main()
{
FILE *fp;
fp = fopen("file.txt", "w");
fputc('a', fp);
fclose(fp);
}
If we will open the file.txt file then we will see the following output:
No comments:
Post a Comment
If you have any doubts, please discuss here...👇