文件名称: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
相关搜索: lseek
(系统自动生成,下载前可以参看下载内容)
下载文件列表
4.doc