设为首页
收藏本站
用户名
Email
自动登录
找回密码
密码
登录
注册
快捷导航
平台
Portal
论坛
BBS
文库
项目
群组
Group
我的博客
Space
搜索
搜索
热搜:
shell
linux
mysql
本版
用户
LinuxSir.cn,穿越时空的Linuxsir!
»
论坛
›
编程开发讨论区 —— LinuxSir.cn
›
Linux 程序设计专题讨论
›
sleep的问题
返回列表
查看:
893
|
回复:
9
sleep的问题
[复制链接]
macarthor
macarthor
当前离线
积分
1551
IP卡
狗仔卡
发表于 2005-6-13 13:12:14
|
显示全部楼层
|
阅读模式
#include <stdio.h>
const int n = 5;
int main(){
int i = 0;
printf("Waiting for %d seconds to exit ", n);
for(; i < n; i++){
sleep(1);
printf(".");
}
printf("\n");
return 0;
}
复制代码
我想在第一个printf后边每一秒输出一个.,就像xp安装启动盘那样的
可是会延迟n秒以后把printf和n个.一起打印出来
怎么办呢?
回复
使用道具
举报
提升卡
置顶卡
沉默卡
喧嚣卡
变色卡
显身卡
firemoth
firemoth
当前离线
积分
176
IP卡
狗仔卡
发表于 2005-6-13 13:48:13
|
显示全部楼层
应该是因为缓存吧
用无缓冲试试
回复
支持
反对
使用道具
举报
显身卡
macarthor
macarthor
当前离线
积分
1551
IP卡
狗仔卡
楼主
|
发表于 2005-6-13 13:54:47
|
显示全部楼层
大蝦給講講吧
回复
支持
反对
使用道具
举报
显身卡
JBug
JBug
当前离线
积分
358
IP卡
狗仔卡
发表于 2005-6-13 13:55:02
|
显示全部楼层
用fflush(stdout)
回复
支持
反对
使用道具
举报
显身卡
firemoth
firemoth
当前离线
积分
176
IP卡
狗仔卡
发表于 2005-6-13 13:57:37
|
显示全部楼层
#include <stdio.h>
int main(void)
{
int n = 5, i;
printf("wait for %d to continue\n", n);
setbuf(stdout, NULL);
for(i = 0; i < n; ++i)
{
sleep(1);
printf(".");
}
printf("\n");
return 0;
}
复制代码
回复
支持
反对
使用道具
举报
显身卡
macarthor
macarthor
当前离线
积分
1551
IP卡
狗仔卡
楼主
|
发表于 2005-6-13 14:19:46
|
显示全部楼层
好像用fflush不行,而setbuf可以
看暸它們的man,但是理解不深
可以給齣相關的網頁嗎?
謝謝!
回复
支持
反对
使用道具
举报
显身卡
Tetris
Tetris
当前离线
积分
264
IP卡
狗仔卡
发表于 2005-6-13 14:29:04
|
显示全部楼层
有什么不好理解的!
#include <stdio.h>
int main(void)
{
int n = 5, i;
printf("wait for %d to continue\n", n);
for(i = 0; i < n; ++i)
{
sleep(1);
printf(".");
fflush(stdout);
}
printf("\n");
return 0;
}
复制代码
搞定
回复
支持
反对
使用道具
举报
显身卡
macarthor
macarthor
当前离线
积分
1551
IP卡
狗仔卡
楼主
|
发表于 2005-6-13 14:31:44
|
显示全部楼层
原来是放在for循环里边啊
我说的理解不深,是关于缓冲区的,这个缓冲区是指控制台的吧?
回复
支持
反对
使用道具
举报
显身卡
Peter74
Peter74
当前离线
积分
118
IP卡
狗仔卡
发表于 2005-6-13 15:13:41
|
显示全部楼层
use this function "setitimer"
回复
支持
反对
使用道具
举报
显身卡
nait
nait
当前离线
积分
952
IP卡
狗仔卡
发表于 2005-6-13 19:32:18
|
显示全部楼层
Post by
macarthor
原来是放在for循环里边啊
我说的理解不深,是关于缓冲区的,这个缓冲区是指控制台的吧?
apue里解释的够详细了,去看看吧
回复
支持
反对
使用道具
举报
显身卡
返回列表
高级模式
B
Color
Image
Link
Quote
Code
Smilies
您需要登录后才可以回帖
登录
|
注册
本版积分规则
发表回复
回帖后跳转到最后一页
浏览过的版块
服务器架设、应用、维护
Copyright © 2002-2023
LinuxSir.cn
(http://www.linuxsir.cn/) 版权所有 All Rights Reserved.
Powered by
RedflagLinux!
技术支持:
中科红旗
|
京ICP备19024520号
快速回复
返回顶部
返回列表