Write a C program to generate random temporary file names

0

Here's an example C program that generates a random temporary file name using the tmpnam() function:


In this program, the tmpnam() function is used to generate a unique temporary file name, which is stored in the "temp_file_name" character array. The L_tmpnam macro is used to define the size of the array, which is needed to hold the result of the tmpnam() function. The generated file name is then printed to the console.


You can also use the rand() function to generate a random number, and then use it as a suffix of the file name, like this:

This will generate a unique file name like tmpfile_12345, where 12345 is a random number.


Please note that the tmpnam() function is considered to be a legacy function and it is recommended to use the tmpfile() function or the mkstemp() function instead, which are considered to be more secure.

Post a Comment

0Comments
Post a Comment (0)