In this tutorial, you will learn about the tmpfile()
function in c programming language. tmpfile()
function is defined in the “stdio.h” header file. By using this function in your c program to create a temproray files and it will always return the pointer value after creating the temporary file.
Below is the example of tmpfile()
method. Copy the below c program and execute it with the help of c compiler to create the temp file in c program.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #include <stdio.h> int main() { char str[] = "Hello World!"; int x = 0; FILE* tmp = tmpfile(); if (tmp == NULL) { puts("Unable to create temp file"); return 0; } puts("Your temporary file has been created.\n"); while (str[x] != '0') { fputc(str[x], tmp); i++; } rewind(tmp); while (!feof(tmp)) putchar(fgetc(tmp)); } |
Your temporary file has been created.
Hello World!
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.