문제

I have the following code example (in windows):

int fd = _dup(fileno(stdout));
freopen("tmp","w",stdout);

printf("1111");
close(stdout);

char buf[100];

FILE *fp;   
fp = fopen("tmp","r");//in this line fd turns to be 0
if(NULL == fp) return -1;
if(fgets(buf,100 , fp) != NULL );
else return -1
fclose(fp);

I need the value of fd for the futher use.How can I read from file without losing the fd value?

도움이 되었습니까?

해결책

I bet that either buf is declared smaller than 100 or the fgets call is in fact with a number larger than 100.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top