struct 用法的示例

源程序:系统调用

#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <fcntl.h>
#include <time.h>

int main()
{
struct stat buf;// 关于文件状态信息的机构体
int fd=open("test.c",O_RDONLY|O_WRONLY);
if(fd==-1)
{
printf("open error");
}
fstat(fd,&buf);
printf("uid= %d\n",buf.st_uid);//st_uid 文件属主的用户身份标识

char *c_time=ctime(&buf.st_ctime);//时间转化为本地时间
printf("st_ctime= %s \n",c_time);
return 0;
}


标准函数库里的函数不能处理使用~的参数

系统调用
ioctl 来操作硬件
管道定向输入 | ,< ,>,
echo hello |simple_read //向simple_read 写入hello
simple_read <1.txt  //输入文件

open需要的头文件
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>

用户掩码 umask变量保护文件创建这的利益0421

分别为 用户 ,组,其他 和文件的属性一样

          

一个程序中一次能打开的文件个数有limits.h 中的OPEN_MAX定义,但posix规定要大于16个
printf函数把自己的输出送到标准输出设备中去,fprintf函数把自己的输出送到某个特定的文件流去,sprintf函数把自己的输出和一个结尾用的空字符写到作为参数传递过来的字符串s里去。这个字符串必须足够大,以便能够容纳所有输出数据。
%c 输出一个字符
%s 输出一个字符串
%e 输出科学计数法

%%才可输出“%'



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值