|
|
1>
[code:1:6c433fc056]#include <time.h>
#include <stdio.h>
int main(void)
{
time_t systime = time(NULL);
printf("%s", ctime( & systime) );
return 0;
}
[andy@ANDY qn]$ ./a.out
Fri Apr 9 22:31:12 2004 //为什么会自动换行呢?
[/code:1:6c433fc056]
2>
我在LINUX下面用getch()函数,它是curses.h头文件里的.
我写的是CPP程序.为什么包含了还不行呢?
有没有人用过?
| parady 回复于:2004-04-10 23:44:46
| 程序如下:
[code:1:04c6f6ccc5]
#include <time.h>
#include <stdio.h>
int main(void)
{
char *p;
time_t systime = time(NULL);
p=ctime(&systime);
while(1)
{
if(*p == '\n')
{
printf("get a newline\n");
break;
}
printf("%c",*p);
p++;
}
printf("%s", ctime( & systime) );
return 0;
}[/code:1:04c6f6ccc5]
结果如下:
[code:1:04c6f6ccc5]
$./a.out
Sat Apr 10 23:22:46 2004get a newline
Sat Apr 10 23:22:46 2004
[/code:1:04c6f6ccc5]
ctime返回char *,该指针所指的字符串最后是一个换行符.
| | THEBEST 回复于:2004-04-11 12:10:21
| 2>
我在LINUX下面用getch()函数,它是curses.h头文件里的.
我写的是CPP程序.为什么包含了还不行呢?
有没有人用过?
| | lenovo 回复于:2004-04-11 12:11:07
| [quote:fb119688c9="THEBEST"]2>
我在LINUX下面用getch()函数,它是curses.h头文件里的.
我写的是CPP程序.为什么包含了还不行呢?
有没有人用过?[/quote:fb119688c9]
你要包含它的库,大概是-lcurses吧。
| | jjj007 回复于:2004-05-13 11:43:12
| 在你想服务器请求时间的时候,服务器会在时间的最后加上"\r\n"的,你可以看一下《unix网络编程 卷1》,第一章就有。
| | windflowers1976 回复于:2004-05-13 12:37:25
| [quote:da187ec324="jjj007"]在你想服务器请求时间的时候,服务器会在时间的最后加上"\r\n"的,你可以看一下《unix网络编程 卷1》,第一章就有。[/quote:da187ec324]
ctime 是向服务器请求时间吗,不要误导.
函数ctime加回车就是加回车,需要自己的实现的话可以使用strftime函数.
[code:1:da187ec324]///////////////////////////////////////////////////////////////////////////////
// 函数说明 : 利用类似系统的时间格式获取时间字符串
// 输入参数 :
// 输出参数 : strTimeBuf
// 返回值 : const char *
// 使用说明 : 若输出长度==最大长度,可能报错2003/09/01
///////////////////////////////////////////////////////////////////////////////
const char * OYCL_CDateTime::Format( OUT char *strTimeBuf, IN int nMaxTimeSize, IN const char *strTimeFmt )
{
int ret = 0;
if ( strTimeBuf != NULL && strTimeFmt != NULL )
{
ret = strftime ( strTimeBuf, nMaxTimeSize, strTimeFmt, &m_stTime );
//TraceLog ( stdout, __LINE__, "", __FILE__, "FMT %s, BUF =%s, ret = %d", strTimeFmt, strTimeBuf, ret );
}
// zero return, 可能存在某错误,如长度越界
if ( ret == 0 )
{
//TraceLog ( stdout, __LINE__, "", __FILE__, "FMT %s, BUF %s, ret %d, error %s", strTimeFmt, strTimeBuf, ret, strerror(errno) );
}
return strTimeBuf;
}[/code:1:da187ec324]
| | jjj007 回复于:2004-07-21 02:32:04
| [quote:c8253751a1="windflowers1976"]ctime 是向服务器请求时间吗,不要误导.[/quote:c8253751a1]你什么时候看到我说ctime()是向服务器请求时间了?!不要误导!
| | chuangxiang79 回复于:2004-09-05 19:06:14
| 在编译时加-lcurses
| |
|