【发布时间】:2011-10-13 16:19:02
【问题描述】:
我正在尝试使用 seek 在 c 编程中获取文件大小。我不能使用fseek、stat.size 或ftell,我需要在其中运行一个自定义操作系统 UNIX。
如何仅使用 seek 找出文件大小?可能吗?
FILE *fd = open(argv[1], "r");
if(fd == NULL)
{
printf("Not able to open the file : %s\n", argv[1]);
return;
}
// Set the pointer to the end
seek(fd, 0, SEEK_END);
【问题讨论】:
-
为什么不能使用 fseek、stat.size 或 ftell?你可以使用 getch() 吗?这是我能想到的唯一方法。
-
你说的
seek函数是什么? -
我的操作系统类中有一个定制的操作系统。它只有特定的打开、读取、写入功能。没有 fopen,ftell 存在。所以有点麻烦。