Skip to content

Instantly share code, notes, and snippets.

@mohamad-wael
Created May 8, 2021 02:00
Show Gist options
  • Save mohamad-wael/4df4911b769419451e6f2f91eaa1a5b5 to your computer and use it in GitHub Desktop.
Save mohamad-wael/4df4911b769419451e6f2f91eaa1a5b5 to your computer and use it in GitHub Desktop.
The C tmpfile function demo
#include <stdio.h>
#include <stdlib.h>
/* tmpfile function demo program . */
int
main
(int argc , char * argv [ ] ){
FILE * tmp = tmpfile ( );
if (!tmp ){
perror (NULL );
exit (EXIT_FAILURE );}
unsigned char dataOut [2 ] = {0x11 , 0x12 };
fputc (dataOut [0 ] , tmp );
fputc (dataOut [1 ] , tmp );
rewind (tmp );
unsigned char dataIn [2 ];
dataIn [0 ] = fgetc (tmp );
dataIn [1 ] = fgetc (tmp );
printf ("%#x\n%#x\n" , dataIn [0 ] , dataIn [1 ] );
/* Output :
0x11
0x12 */
if (fclose (tmp ) != 0 ){
perror (NULL );
exit (EXIT_FAILURE ); }
return 0;}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment