/ 我测试了 Dev-C++ 5.11 (Mngv) gcc,但不工作。在 Code:: Block 中使用 Borland 5.5 没问题。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
int main(int argc, char *argv[]) {
char filename[L_tmpnam];
char *strs[] = {"Hello\n","Goodbye\n","Cat\n","Dog\n",NULL};
char **mover = strs;
char line[80],command[80];
FILE *fp;
fp = tmpfile();
for(; *mover != NULL; mover++) fputs(*mover,fp);
rewind(fp);
while(fgets(line,80,fp))printf("%s",line);
fclose(fp);
if(tmpnam(filename) == NULL){
printf("Could not get non-conflicting file name\n");
exit(EXIT_FAILURE);
}
printf("\nFilename obtained is: %s\n\n",filename);
fp = fopen(filename, "w+");
for(mover = strs; *mover != NULL; mover++) fputs(*mover, fp);
rewind(fp);
while(fgets(line,80,fp)) printf("%s",line);
putchar('\n');
fclose(fp);
return 0;
}