Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Linux by (6.1k points)

I need to create .log file using C. However, I cannot use the usual way to create this. The file is created but it cannot write. Can anyone explain?

f = fopen("file.log", "w"); 

fprintf(f, "print this");

1 Answer

0 votes
by (11.7k points)

In Linux, it is pretty simple to create a .log file:

Create a file using the code given below in the same folder where you have placed your C code.

FILE *fp; 

fp = fopen ("data.log", "w"); 

fprintf(fp, "print this");

Path can also be specified where you want to create your file. 

FILE *fp; 

fp = fopen ("E://data.log", "w"); 

fprintf(fp, "print this"); 

}

Related questions

0 votes
1 answer
asked Dec 5, 2020 in Linux by blackindya (18.4k points)
0 votes
3 answers

1.2k questions

2.7k answers

501 comments

693 users

Browse Categories

...