C language realizes printf peer output (refresh display)

When the blogger is writing a program recently, due to the large amount of processing data and the long running time of the program, it is necessary to output the processing progress to the screen in real time

Normally we use the printf function to output the data to be displayed to the screen:

printf("Combining the %d INS/GNSS data using the %d GNSS value\n",kfn, kgnss);

In order to facilitate viewing, it needs to be displayed in a new line each time, as shown in the figure below. This line-by-line display is very inconvenient to view, so there is a need to realize peer-to-peer output. If you want to peer-to-peer output, you only need to
insert image description here
overwrite the content of the last output. Therefore, You only need to move the starting point (cursor position) of the next output to the front of the newline, then we need to \nreplace the newline with\r

printf("Combining the %d INS/GNSS data using the %d GNSS value\r",kfn, kgnss);

In this way, peer coverage output can be achieved, that is, the display is refreshed.
insert image description here
Readers can use the following small code to test the effect and then apply it to their own programs.

int view=0;
for(view=0;view<100;view++)
{
    
    
   printf("view %d\r",view);
}

Guess you like

Origin blog.csdn.net/absll/article/details/128215033