70,037
社区成员
发帖
与我相关
我的任务
分享#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
int main()
{
char result[100];
FILE *fp = NULL;
int fd = 0;
fp = fopen("alexTest", "r");
fd = fileno(fp);
lseek(fd, 10, SEEK_SET);
fscanf(fp, "%s\n", result);
printf("%s\n", result);
lseek(fd, 0, SEEK_SET); //这一步执行完之后,文件指针怎么没有转到文件头?文件指针好像没动
fscanf(fp, "%s\n", result);
printf("%s\n", result);
fclose(fp);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
int main()
{
char result[100];
FILE *fp = NULL;
int fd = 0;
int off = 0;
fp = fopen("t.txt", "r");
fd = fileno(fp);
off = lseek(fd, 10, SEEK_SET);
printf("off=%d\n", off);
fscanf(fp, "%s\n", result);
printf("%s\n", result);
fseek(fp, 0, SEEK_SET); /*文件指针回到文件起始处*/
off = lseek(fd, 0, SEEK_SET);
printf("off=%d\n", off);
fscanf(fp, "%s\n", result);
printf("%s\n", result);
fclose(fp);
return 0;
}