fflush函数使用

   int i;
   
   for(i=0; i<10; i++){
   
       printf("\r%d",);
       fflush(stdout);//清除缓冲区
       sleep(1);
   }
运行:跟手表的秒钟一样


     FILE *fp;  
     if ((fp = fopen("test", "wb")) == NULL)
    {
         printf("Cannot open file.\n");
         exit(1);
     }
 
     char ch = 'i';
     int i;
     for(i = 0; i < 5; i++)
     {
         fwrite(&ch, sizeof(ch), 1, fp);
         //fflush(fp);
     }
     fclose(fp);
  

你可能感兴趣的:(c)