comma separated expression in while loop in C

前端 未结 5 1925
慢半拍i
慢半拍i 2020-11-30 07:50

I never saw such a while statement before.

while(printf(\"> \"), fgets(str, 100, stdin), !feof(stdin)) {
..
..
}

I read

5条回答
  •  渐次进展
    2020-11-30 08:25

    while(printf("> "), fgets(str, 100, stdin), !feof(stdin)) {
    ..
    ..
    }
    

    Commas inside a while behaves more like this:

    int feof_wrapper(FILE * stream)
    {
       printf("> ");
       fgets(str, 100, stream);
       return feof(stream);
    }
    
    while(!feof_wrapper(stdin)) {
    ..
    ..
    }
    

提交回复
热议问题