Created
May 8, 2021 02:00
-
-
Save mohamad-wael/4df4911b769419451e6f2f91eaa1a5b5 to your computer and use it in GitHub Desktop.
The C tmpfile function demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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