How to use tmpfile() function to create temporary binary file for update ("wb+") in C

1 Answer

0 votes
#include <stdio.h>
   
int main(void)
{
	char buf[64] = "temp file";
	FILE *fp = tmpfile();

	fputs(buf, fp);

	buf[0] = '\0';
	printf("buf = %s\n", buf);

	rewind(fp);
	fgets(buf, 64, fp);
    printf("buf = %s\n", buf);

	// Temporary file is closed and deleted when the program exits normally

    return 0;
}
  
/*
run:
  
buf =
buf = temp file

*/

 



answered May 7, 2016 by avibootz
edited Feb 3, 2023 by avibootz

Related questions

2 answers 214 views
2 answers 180 views
180 views asked Dec 1, 2023 by avibootz
2 answers 261 views
1 answer 212 views
212 views asked Jul 21, 2016 by avibootz
1 answer 203 views
...