文件名称:4
介绍说明--下载内容来自于网络,使用问题请自行百度
学会对文件的记录锁定,及解锁。#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
int main()
{
int fd
int i
struct {
char name[20]
uint ID
int age
} myrec
fd =open(\"name\", O_RDWR|O_CREAT, 0755)
if (fd == -1) return -1
printf(\"Input your name:\") scanf(\"%s\", myrec.name)
printf(\"Inpute your ID :\") scanf(\"%d\", &myrec.ID)
printf(\"Input your age :\") scanf(\"%d\", &myrec.age)
lseek(fd, 0,SEEK_END)
lockf(fd, 1, 0)
write(fd, (void *)&myrec, sizeof(myrec))
lockf(fd, 0 ,0)
return 0
}
执行命令cc lock.c –o lock.out
Chmod +x lock.out
./lock.out
#include <unistd.h>
#include <fcntl.h>
int main()
{
int fd
int i
struct {
char name[20]
uint ID
int age
} myrec
fd =open(\"name\", O_RDWR|O_CREAT, 0755)
if (fd == -1) return -1
printf(\"Input your name:\") scanf(\"%s\", myrec.name)
printf(\"Inpute your ID :\") scanf(\"%d\", &myrec.ID)
printf(\"Input your age :\") scanf(\"%d\", &myrec.age)
lseek(fd, 0,SEEK_END)
lockf(fd, 1, 0)
write(fd, (void *)&myrec, sizeof(myrec))
lockf(fd, 0 ,0)
return 0
}
执行命令cc lock.c –o lock.out
Chmod +x lock.out
./lock.out
(系统自动生成,下载前可以参看下载内容)
下载文件列表
4.doc
本网站为编程资源及源代码搜集、介绍的搜索网站,版权归原作者所有! 粤ICP备11031372号
1999-2046 搜珍网 All Rights Reserved.