![C program to add new line in existing file. C program to add new line in existing file.](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5W-DL3KNohL6EWeOyZmng3sgxbB1ZXcKkdiT-bVA-ZEjOpT4YDcgQeaiECz_FgdB7deg35E_VA5SyG6bDmG-WofLycNoHWGFqCjI6r3C6wLmKdHde4l7gAyBjjjLeEfz-RiE5o-62mkxd/s640/add+new+line+in+existing+file.jpg)
Program:
#include <stdio.h>
/* C program to add new line in existing file by SlashMyCode.com */
int main()
{
char sentence[1000];
FILE *fptr;
fptr = fopen("file.txt", "w"); /*To open file*/
printf("Enter a sentence:\n");
gets(sentence);
fprintf(fptr,"%s", sentence); /*To write in a file*/
fclose(fptr); /*To close file*/
/* C program to add new line in existing file by SlashMyCode.com */
getch();
}
NOTE: Program will create new file if file doesn't exist in directory.
Output:
as you can see here, the sentence entered in program has been added in file.txt
No comments:
Post a Comment
Feel free to ask us any question regarding this post