Created
September 11, 2017 08:24
-
-
Save hirokuma/d006e4d8710ec8fdfc314034afa4c6a9 to your computer and use it in GitHub Desktop.
fflush(stdout)するとOK
This file contains 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 <unistd.h> | |
#include <sys/stat.h> | |
#include <sys/types.h> | |
#include <fcntl.h> | |
int main(void) | |
{ | |
const char *FNAME[] = { | |
"1.txt", "2.txt", "3.txt" | |
}; | |
for (int lp = 0; lp < 3; lp++) { | |
int fd = open(FNAME[lp], O_CREAT | O_WRONLY, 0644); | |
close(1); | |
int fd2 = dup(fd); | |
fprintf(stderr, "fd=%d, fd2=%d\n", fd, fd2); | |
fprintf(stdout, "lp=%d, %s\n", lp, FNAME[lp]); | |
fflush(stdout); | |
close(fd); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment