I'm writing a program to manipulate and input file/files...But the problem is when it open the file and writes to it. It deletes the rest of the file leaving what the program put in it. How can I manipulate the program to enter the char/chars in a file without deleting the rest of the file. Ex. C program
EX.
#include<studio.h>
.
.
.
.
main()
{
FILE* f_read;
FILE* f_write;
char* buf[201];
f_write = fopen("/tmp/file", "w"
;
if (fseek(f_write, 0L, SEEK_SET) < 0) {
perror("fseek(f_write, 5L, SEEK_SET)"
;
}
fputs("#hello", f_write);
if (fclose(f_write) == EOF) {
perror("Error when closing file:"
;
}
return 0;
}
before c program
file:
test1
test1
test1
test1
test1
#
__________________________________
after c program
file:
#hello
#
EX.
#include<studio.h>
.
.
.
.
main()
{
FILE* f_read;
FILE* f_write;
char* buf[201];
f_write = fopen("/tmp/file", "w"
if (fseek(f_write, 0L, SEEK_SET) < 0) {
perror("fseek(f_write, 5L, SEEK_SET)"
}
fputs("#hello", f_write);
if (fclose(f_write) == EOF) {
perror("Error when closing file:"
}
return 0;
}
before c program
file:
test1
test1
test1
test1
test1
#
__________________________________
after c program
file:
#hello
#