回车(\n)概念 数据换行,针对标准输出的时候,还有刷新缓冲区 #include <stdio.h> #include<unistd.h> int main() { printf("hello world!\n"); sleep(3); return 0; } //中端显示 hello world,三秒后程序执行结束 #include <stdio.h> #include<unistd.h> int main() { printf("hello world!"); sleep(3); return 0; } //三秒后中端显示 hello world,随即程序结束 #include <stdio.h> #include<unistd.h> int main() { printf("hello world!"); fflush(stdout);//刷新缓冲区 sleep(3); return 0; } //中端显示 hello world,三秒后程序执行结束 换行(\r)概念 回车符,让光标移动到起始位置 ps:如果需要将数据打印到中端,则要加上:fflush(stdout),于是可以写一个进度条小程序: 1//一个简单的进度条程序 2 #include<stdio.h> 3 #include<stdlib.h> 4 #include<unistd.h> 5 int main() 6 { 7 char buf[11] = {0}; 8 int i = 0; 9 for(i; i < 11; ++i) 10 { 11 buf[i] = '-'; 12 printf("%s\r",buf); 13 fflush(stdout); 14 sleep(1); 15 } 16 return 0; 17 }