sprintf练习代码

来源:互联网 发布:淘宝能运到英国吗 编辑:程序博客网 时间:2024/06/05 00:21
#include<stdio.h>
#include <sys/types.h>
#include<fcntl.h>
#include<sys/wait.h>
#include<string.h>
#include<time.h>
int main()
{
time_t t = time(0);
char* str ="系统时间被修改";
char buf[200];
char s[32];
strftime(s, sizeof(s), "%Y-%m-%d %H:%M:%S", localtime(&t));
sprintf(buf,"%s:%s:进程id=%d",s,str,getpid());
int fd=open("/tmp/dameon.log",O_CREAT|O_WRONLY|O_APPEND,0600);
int len = strlen(buf);
write(fd,buf,len+1);


printf("%s\n",buf);
}
0 0
原创粉丝点击