Advertisement
FILE *fopen(const char *filename, const char *mode)
File Mode | Description |
---|---|
"w" | Searches for the file and if the file is found, its content are overwritten. If file is not found, a new file is created. Allows you to write to the file. |
#include<stdio.h>
#include<conio.h>
int main()
{
char str[100] = "Hello, how are you going? Have a pleasant day ahead!";
/* this will create the file in the directory where this C program file is stored */
FILE *fw = fopen("File2.txt", "w");
char ch;
int i=0;
while(str[i]!='\0')
{
fputc(str[i], fw);
i++;
}
fclose(fw);
return 0;
}
Hello, how are you going? Have a pleasant day ahead!
Advertisement
#include<stdio.h>
#include<conio.h>
int main()
{
char str[200];
printf("Enter the content you want to write to a file : \n");
gets(str);
/* this will create the file in the directory where this C program file is stored */
FILE *fw = fopen("File3.txt", "w");
char ch;
int i=0;
while(str[i]!='\0')
{
fputc(str[i], fw);
i++;
}
fclose(fw);
return 0;
}
Enter the content you want to write to a file :
Always look at the bright side of life. Keep smiling and never give up!
Always look at the bright side of life. Keep smiling and never give up!
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement