Print spinning cursor in a terminal running application using C

后端 未结 5 986
Happy的楠姐
Happy的楠姐 2021-02-01 07:15

How would I print a spinning curser in a utility that runs in a terminal using standard C?

I\'m looking for something that prints: \\ | / - over and over in the same pos

5条回答
  •  一整个雨季
    2021-02-01 08:12

    You could use the backspace character (\b) like this:

    printf("processing... |");
    fflush(stdout);
    // do something
    printf("\b/");
    fflush(stdout);
    // do some more
    printf("\b-");
    fflush(stdout);
    

    etc. You need the fflush(stdout) because normally stdout is buffered until you output a newline.

提交回复
热议问题