ch12-tmpfile.c

来自「linux编程精髓 源代码」· C语言 代码 · 共 25 行

C
25
字号
/* ch12-tmpfile.c --- demonstrate tmpfile().                      Error checking omitted for brevity */#include <stdio.h>int main(void){	static char mesg[] =		"Here's lookin' at you, kid!";	/* beats "hello, world" */	FILE *fp;	char buf[BUFSIZ];	fp = tmpfile();				/* Get temp file */	fprintf(fp, "%s", mesg);		/* Write to it */	fflush(fp);				/* Force it out */	rewind(fp);				/* Move to front */	fgets(buf, sizeof buf, fp);		/* Read contents */	printf("Got back <%s>\n", buf);		/* Print retrieved data */	fclose(fp);				/* Close file, goes away */	return 0;				/* All done */}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?