程序的小错误。找了半天都没看到,发在这里请帮忙查下

ryangio 2010-04-20 08:39:41
编译环境 GCC
题目:求一个文件的大小

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
int main(int argc, char *argv[])
{
int file_size;
int fd;
if (argc < 2)
{
printf("no input file\n");
return -1;
}
fd = open(argv[1], O_RDONLY);
if (fd == -1)
{
printf("open file %s failed\n", argv[]);
return -1;
}
file_size = lseek(fd, 0, SEEK_END);
if (file_size >= 0)
{
printf("%s's size is: %d", file_size);
}
else
{
perror(" lseek error");
}
close(fd);
}
...全文
23 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
ryangio 2010-04-20
  • 打赏
  • 举报
回复
我也刚看到。。谢谢。分都给你了哈哈
柯本 2010-04-20
  • 打赏
  • 举报
回复

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
int main(int argc, char *argv[])
{
int file_size;
int fd;
if (argc < 2)
{
printf("no input file\n");
return -1;
}
fd = open(argv[1], O_RDONLY);
if (fd == -1)
{
printf("open file %s failed\n", argv[1]); //少一个下标
return -1;
}
file_size = lseek(fd, 0, SEEK_END);
if (file_size >= 0)
{
printf("%s's size is: %d", argv[1],file_size); //少一个参数
}
else
{
perror(" lseek error");
}
close(fd);
}

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧