siunix
asked on
write to a file
Hi,
How can I write a couple of lines to a file using c?
ex: I want a simple c program which will write three lines to a file call
/tmp/file1 under solaris.
after I run the c program, it should write the three lines to the /tmp/file1
/tmp/file1 contains:
#! is line one
line2
line3 is good
thanks in advance
How can I write a couple of lines to a file using c?
ex: I want a simple c program which will write three lines to a file call
/tmp/file1 under solaris.
after I run the c program, it should write the three lines to the /tmp/file1
/tmp/file1 contains:
#! is line one
line2
line3 is good
thanks in advance
void g()
{
FILE * f;
f = fopen("/tmp/file1", "w");
//Code for writing into the file
//goes here...
fclose(f);
}
{
FILE * f;
f = fopen("/tmp/file1", "w");
//Code for writing into the file
//goes here...
fclose(f);
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
great answer.
thanks for all your help.
thanks for all your help.
ASKER
I try:
fprintf(fptr, "fi");
and it does not write "fi" to the file.
is there a fix for this?
thanks
fprintf(fptr, "fi");
and it does not write "fi" to the file.
is there a fix for this?
thanks
fptr = fopen("w", "/tmp/file1");
fprintf(fptr, "#! is line one");
fprintf(fptr, "line2");
fprintf(fptr, "line3 is good");
fclose(fptr);