Update printf value on same line instead of new one

后端 未结 8 1188
刺人心
刺人心 2020-12-06 01:25

I would like to know if there is a way in C to overwrite an existing value that has already been printed instead of creating a new line every time or just movin

8条回答
  •  萌比男神i
    2020-12-06 01:51

    Refer to the sample code to understand:

    #include 
    #include 
    
    void myThread(void* ptr) {
        printf("Hello in thread\n");
        int i=0;    
        for(;i<10;i++)
        {
            sleep(1);
            printf(". ");
            fflush(stdout);  //comment this, to see the difference in O/P
        }
        printf("sleep over now\n");
    }
    
    int main(void) {
        pthread_t tid;
        printf("creating a new thread\n");
        pthread_create(&tid, NULL, (void*)myThread, 0);
        printf("going to join with child thread..\n");
        pthread_join(tid, NULL);
        printf("joined..!!\n");
        return 0;
    }
    

    Reference Blog

提交回复
热议问题