创建文件以及删除文件

来源:互联网 发布:淘宝 木头衣柜 编辑:程序博客网 时间:2024/05/16 09:04

一个简单的小例子:

sprintf()实现对int转型成char,从而把时间数据保存成相关的log文件。

strcat()实现对字符串的剪切

open()实现对文件的创建

remove实现对文件的删除

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <time.h>
#include <string.h>

void main()
{

int date = 1234;

char *file;

sprintf(file, "%d", date);

char addr_hour[32] = "/root/zy/telnet/";
printf("changeto_char init is :%s \n", changeto_char);

strcat(addr_hour,changeto_char);
printf("addr_hour is :%s\n", addr_hour);

int fd = open (addr_hour,O_CREAT|O_RDWR);
sleep(3);

printf("删除文件 is :%s\n", addr_hour);
remove(addr_hour);

}

0 0
原创粉丝点击