1. c语言如何让操作完一个函数后继续停留在当前菜单
case 1: output(s);到这你的1次大循环应该是结束了,当然会回到开始的位置,如果你想在结束后回到2集菜单,简单点的方法用 goto,复杂点的方法就得改整个程序了,得再加循环
2. linux下c语言读取文件时让其输出一行停顿几秒的问题
头文件添加:
#include <unistd.h>
#include <stdlib.h>
然后,在输出换行后面加上语句
int ret ;
ret=alarm(2) ; /*调用alarm定时器函数*/
pause() ;
这样就能实现你要的功能了。
3. c语言的函数体用什么开始用什么结束
c语言的函数体用{函数体开始,用}函数结束,函数体的的前面是定义部分,后面是执行部分。
使用示例:
if (argc<3) {
printf (" Error! Not enough arguments. Correct usage is .. " ) ;
printf("c:>eopyfile <source_file> <destination_file> ") ;
exit (1) ;
}
else {
open_files () ;
while (! feof(infile)) {
read_data ( ) ;
write_data() ;
}
close files() ;
}
(3)c语言函数停顿方法扩展阅读
C语言中的大括号,定义和初始化结构体变量
结构体变量的定义方法的样例如下:
typedef struct
{
……
}T_Struct;
该结构体变量的初始化样例如下:
T_Struct tStruct = {0};
4. C语言怎样使被调函数停止一段时间,主函数继续
那就只有多线程了,单线程是不可能实现这种功能的。
单线程的运行就是线性的,A函数调用B函数,B函数不执行return语句,A函数不可能再继续执行。
5. c语言如何用getline或什么的使程序停顿一下
头文件<conio.h>
有一个getch()的函数
这个是等待用户输入任意键,然后继续运行之后的程序
6. C语言如何隔几秒再显示下一句话
首先包含这个头文件包
#include <ctime>
定义2个时间节点。
time_t start,end;//记时标示符
如果你是知道时间的长度的那仅仅好办了。
这样就先给start赋值为当前系统时间,然后end加上输出时间的长度。
在用循环
for(int i=start;i<=end;i+1)(这里可以选择你是隔几秒)
然后输出。
最后给你点获取系统时间一些函数:
vc/c++时间函数
一、MFC类
MFC提供了两个日期和时间类CTime和CTimeSpan,分别代表相对时间和绝对时间。CTime是基于格林威治平均时间(GMT)的,本地的时间由环境变量TZ决定。CTimeSpan代表了时间间隔。
CTime类由下列成员函数:
CTime()
创建一个CTime对象。
GetCurrentTime()
由当前时间创建一个CTime对象。
GetTime()
由CTime对象返回一个time_t变量。
GetYear()
获取CTime对象代表的年。
GetMonth()
获取CTime对象代表的月。
GetDay() 获取CTime对象代表的日期。
GetHour() 获取CTime对象代表的小时。
GetMinute()获取CTime对象代表的分。
GetSecond() 获取CTime对象代表的秒。
GetDayOfWeek() 获取CTime对象代表的周日,1代表周日,2代表周-等等。
Format() 将字符串转换成一个基于本地时区的格式字符串。
FormatGmt() 将字符串转换成一个基于UTC(世界时)的格式字符串。
operator = 赋予新的时间。
operator + 增加CTime和CTimeSpan对象。
operator – 减小CTime和CTimeSpan对象。
operator += CTime对象加一个CTimeSpan对象。
operator -= CTime对象减一个CTimeSpan对象。
operator == 比较两个绝对时间是否相等。
operator != 比较两个绝对时间是否不相等。
operator < 比较两个绝对时间,是否前一个大于后一个。
operator > 比较两个绝对时间,是否前一个小于后一个。
operator >= 比较两个绝对时间,是否前一个大于等于后一个。
operator <= 比较两个绝对时间,是否前一个小于等于后一个
二、总结
首先看几个函数的原型的声明(在time.h中):
clock_t clock( void ) clock_t是用来保存时间的数据类型,是long型
double difftime(time_t time1, time_t time0); 取时间间隔的函数
time_t time(time_t * timer); 日历时间函数
char * asctime(const struct tm * timeptr); 将tm 类的时间结构转化为 固定时间格式
char * ctime(const time_t *timer); 将日历时间转化为 固定时间格式
time_t mktime(struct tm * timeptr); 以年、月、日、时、分、秒等分量保存的时间结构
struct tm * gmtime(const time_t *timer); 将日历时间转化为格林尼治时间
struct tm * localtime(const time_t * timer); 将日历时间转化为当地时间
tm 的定义:
struct tm {
int tm_sec; /* 秒 – 取值区间为[0,59] */
int tm_min; /* 分 - 取值区间为[0,59] */
int tm_hour; /* 时 - 取值区间为[0,23] */
int tm_mday; /* 一个月中的日期 - 取值区间为[1,31] */
int tm_mon; /* 月份(从一月开始,0代表一月) - 取值区间为[0,11] */
int tm_year; /* 年份,其值等于实际年份减去1900 */
int tm_wday; /* 星期 – 取值区间为[0,6],其中0代表星期天,1代表星期一,以此类推
*/
int tm_yday; /* 从每年的1月1日开始的天数 – 取值区间为[0,365],其中0代表1月1日,
1代表1月2日,以此类推 */
int tm_isdst; /* 夏令时标识符,实行夏令时的时候,tm_isdst为正。不实行夏令时的进候
,tm_isdst为0;不了解情况时,tm_isdst()为负。*/}
1.获取间隔时间
1. clock_t start, finish;
long i = 10000000;
double ration;
start = clock();
while( i-- ) ;
finish = clock();
ration = (double)(finish - start) / CLOCKS_PER_SEC;
cout<<ration;
输出的是: i从10000000减到零用的时间,精确到毫秒
2.
double pause1;
time_t start,end;
start = time(NULL);
system("pause");
end = time(NULL);
pause1 =difftime(end,start);
cout<<pause1;
输出的是: 你停顿(pause)的时间,精确到秒
2.获得日历时间
time_t lt;
lt =time(NULL);//(还不清楚带参的和不带参的区别)
cout<<lt;
输出的是: 从1970年1月1日0时0分0秒到此时的秒数
3.获得日期和时间
1. 将日历时间转化为本地时间(格林尼治时间)
struct tm *local
time_t t;
t=time(NULL);
local=localtime(&t);
//local=gmtime(&t);
cout<<local->tm_hour;
2. 以固定的时间格式获得日期和时间:看清这两个函数的参和返回值的类型
char * asctime(const struct tm * timeptr);
char * ctime(const time_t *timer);
1.将日历时间直接转换为 固定的时间格式的日期和时间
char * jieguo;
time_t lt;
lt =time(NULL);
jieguo =ctime(<);
cout<< jieguo;
2.将日历时间经过localtime()和gmtime()转换后在转换为固定的时间格式的日期和时间
struct tm *local;
char * jieguo;
time_t t;
t =time(NULL);
local=localtime(&t);
//local=gmtime(&t);
jieguo=asctime(local);
cout<< jieguo;
4.分解时间转化为日历时间
这里说的分解时间就是以年、月、日、时、分、秒等分量保存的时间结构,在C/C++中是tm结构。我们可
以使用mktime()函数将用tm结构表示的时间转化为日历时间。其函数原型如下:
time_t mktime(struct tm * timeptr);
其返回值就是转化后的日历时间。这样我们就可以先制定一个分解时间,然后对这个时间进行操作了,
下面的例子可以计算出1997年7月1日是星期几:
#include "time.h"
#include "stdio.h"
#include "stdlib.h"
int main(void)
{
struct tm t;
time_t t_of_day;
t.tm_year=1997-1900;
t.tm_mon=6;
t.tm_mday=1;
t.tm_hour=0;
t.tm_min=0;
t.tm_sec=1;
t.tm_isdst=0;
t_of_day=mktime(&t);
printf(ctime(&t_of_day));
return 0;
}
运行结果:
Tue Jul 01 00:00:01 1997
现在注意了,有了mktime()函数,是不是我们可以操作现在之前的任何时间呢?你可以通过这种办法算
出1945年8月15号是星期几吗?答案是否定的。因为这个时间在1970年1月1日之前,所以在大多数编译器
中,这样的程序虽然可以编译通过,但运行时会异常终止。
7. C语言中的sleep() 函数
使用要带上头文件:
#include <windows.h>
Sleep函数:
功 能: 执行挂起一段时间
用 法: unsigned sleep(unsigned seconds);
注意:
1.在VC中使用带上头文件#include <windows.h>,在Linux下,gcc编译器中,使用的头文件因gcc版本的不同而不同#include <unistd.h>
2.在VC中,Sleep中的第一个英文字符为大写的"S" ,在linux下不要大写,在标准C中是sleep, 不要大写,简单的说VC用Sleep, 别的一律使用sleep。
3.在VC中,Sleep()里面的单位,是以毫秒为单位,所以如果想让函数滞留1秒的话,应该是Sleep(1000); 在Linux下,sleep()里面的单位是秒,而不是毫秒。
示例:
#include<dos.h>
int main(void)
{
sound(440);
delay(500);
nosound();
return 0;
}
delay()是循环等待,该进程还在运行,占用处理器。
sleep()不同,它会被挂起,把处理器让给其他的进程。
8. c语言休眠函数怎么写
1、sleep()函数:秒级休眠函数
#include <unistd.h >
unsigned int sleep(unsigned int unSeconds);
参数unSeconds表示需要休眠的秒数;
2、usleep()函数:微秒级休眠函数;
#include <unistd.h>
int usleep(useconds_t lMicroSeconds);
参数lMicroSeconds表示要休眠的微秒数;
#ifndef _SUSECONDS_T
#define _SUSECONDS_T
typedef long suseconds_t; /* signed # of microseconds */
#endif /* _SUSECONDS_T */
类型useconds_t定义在头文件/usr/include/sys/types.h中;
3、nanosleep()函数:纳秒级休眠函数;
#include <time.h>
int nanosleep(const struct timespec* rqtp, struct timespec* rmtp);
4、其它休眠函数:
select()、pselect()、poll();等;
select()函数也可以精确到微秒,pselect()函数也可以精确到纳秒。