Tuesday, October 27, 2020

,

Example program for tmpfile() function in c programming

  •  tmpfile() function in c programming is used to created the temporary file in program and this temporary file will be deleted after  termination of c program.
  • wb+ mode is used to opens file in binary update 
Example program for tmpfile() in c
Example program for tmpfile() function in c programming

 

Syntax :- 

FILE *tmpfile(void) 
  • this function return the file after creating the temporary file.

Program example for tmpfile() function in c


#include <stdio.h>
int main() 
{ 
    char str[] = "Hello function in c"; 
    int i = 0; 
  
    FILE* tmp = tmpfile(); 
    if (tmp == NULL) 
    { 
        puts("Unable to create temp file"); 
        return 0; 
    } 
  
    puts("Temporary file is created\n"); 
    while (str[i] != '\0') 
    { 
        fputc(str[i], tmp); 
        i++; 
    } 
  
    // rewind() function sets the file pointer 
    // at the beginning of the stream. 
    rewind(tmp); 
  
    while (!feof(tmp)) 
        putchar(fgetc(tmp)); 
} 
OUTPUT : -

Temporary file is created
Hello function in c

0 comments:

Post a Comment