Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a temporary text file in C

Tags:

c

I have a text file to read. I would like to read from that file and store into a temporary file. I am not sure how to do this. How do I create a temporary file and do I use fprintf to store in that file?

like image 311
user2794964 Avatar asked Sep 06 '25 03:09

user2794964


1 Answers

You could use the function tmpfile() for that.

The tmpfile() function opens a unique temporary file in binary read/write (w+b) mode. The file will be automatically deleted when it is closed or the program terminates.

Example:

FILE * temp = tmpfile();
if(temp) {
    fprintf(temp, "Hello, Temp!");
}
like image 67
A4L Avatar answered Sep 07 '25 21:09

A4L