From the course: C Programming: Exploring Advanced Concepts and Practical Applications
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Making a temporary file
From the course: C Programming: Exploring Advanced Concepts and Practical Applications
Making a temporary file
- [Presenter] This code uses the mkstemp function to generate a temporary file name. The template is defined here. It can be any text you want, but it must end with six big Xs. These are replaced by randomly generated characters with a prefix unchanged. This function uses this template as its argument, and the value is returned as a file descriptor, not a file handle. It's closed here. The temporary file is created and named in the output. It also appears here in the file explorer. This file shares its name with no other file in the directory, so you can use it temporarily. Say you need to create 10 temporary files based on the same template. This code uses a loop to call the mkstemp function 10 times, each time putting the name and then closing the file descriptor. The program catches the error. The error is an invalid argument. What happens is that the template is replaced by the file name, which is output here, because the template is now invalid, it has no big X characters. The…
Contents
-
-
-
-
-
-
-
-
(Locked)
Creating enumerated constants2m 34s
-
(Locked)
Exploring data type qualifiers2m 48s
-
(Locked)
Outputting accurate error messages2m 48s
-
(Locked)
Making a temporary file3m 45s
-
(Locked)
Modifying how a program quits3m 23s
-
(Locked)
Reviewing useful constants3m 43s
-
(Locked)
Challenge: Write an informative program1m 38s
-
(Locked)
-