Skip to content

Instantly share code, notes, and snippets.

@mohamad-wael
Last active May 8, 2021 14:47
Show Gist options
  • Save mohamad-wael/797eca382fe64a32cb14eaf923b1f2ad to your computer and use it in GitHub Desktop.
Save mohamad-wael/797eca382fe64a32cb14eaf923b1f2ad to your computer and use it in GitHub Desktop.
How to use the tmpnam function in c ?
#include <stdio.h>
#include <stdlib.h>
int
main
(int argc , char * argv [ ] ){
char tmp_path [L_tmpnam + 1 ];
tmpnam (tmp_path );
/*Generate a temp path .*/
printf ("%s\n" , tmp_path );
/* Output in Unix like OS :
/var/tmp/tmp.0.9oxTFK
Output in windows :
\s2ro.
Under windows \ indicates
that the name is valid under
the current working directory .*/
char * tmp_path_1 = tmpnam (NULL );
printf ("%s\n" , tmp_path_1 );
/* Output in Unix like OS :
/var/tmp/tmp.1.Qo9D8Z
Output in windows :
\s3rg.1*/
tmpnam (NULL );
printf ("%s\n" , tmp_path_1 );
/* Output in Unix Like OS :
/var/tmp/tmp.2.wnTK4D
Output in windows :
\s3rg.2 */ }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment