Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: C++
Expertise: Intermediate
Nov 6, 2000

Creating a Temporary File

Many applications create temporary files that exist as long as the program is running and are later discarded. For example, a Web browser can store a list of pages that have been viewed during the current browsing session and redisplay them when you press "Back". The problem is that most applications don't delete these temporary files after the application is closed. Instead, they store them in a special directory that you have to clean manually. A better approach is to use the standard function tmpfile(), which is declared in <stdio.h> as follows:

 
FILE * tmpfile();

tmpfile() opens a temporary file for read/write operations and returns a pointer to to that file. tmpfile() uses unique filenames to avoid conflicts with any existing files. The temporary files created by tmpname() are automatically deleted when the program terminates so you don't have to manually delete them.

Danny Kalev
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap