C语言写个输出文件大小的程序
WriteaCprogramthattakesasinglefilenameasaparameterandoutputstostandardoutputthesizeof...
Write a C program that takes a single file name as a parameter and
outputs to standard output the size of the file in bytes. You may assume the file
exists and it is just a regular file. Place your answer in the file called 'mysize.c' in the
Q3 directory. (hint - “man 2 stat”) When run from the command line you should see :
$ ./mysize 100bytefile
100
$ ./mysize emptyfile
0 展开
outputs to standard output the size of the file in bytes. You may assume the file
exists and it is just a regular file. Place your answer in the file called 'mysize.c' in the
Q3 directory. (hint - “man 2 stat”) When run from the command line you should see :
$ ./mysize 100bytefile
100
$ ./mysize emptyfile
0 展开
展开全部
像楼上的,打开一个文件,fseek函数把文件位置移动到末端,然后ftell获取文件当然位置并返回就是文件大小了,
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
//mysize.c
#include <stdio.h>
int main(int argc, char* argv[])
{
long int iFileLen;
FILE *pFile;
if(argc==1){
printf("usage: mysize <filename>\n");
return 0;}
pFile = fopen( argv[1], "rb" );
if ( pFile == NULL ) {
printf("file not found\n");
return 1;}
fseek( pFile, 0, SEEK_END );
iFileLen = ftell( pFile );
fclose( pFile );
printf("%ld\n",iFileLen);
return 0;
}
#include <stdio.h>
int main(int argc, char* argv[])
{
long int iFileLen;
FILE *pFile;
if(argc==1){
printf("usage: mysize <filename>\n");
return 0;}
pFile = fopen( argv[1], "rb" );
if ( pFile == NULL ) {
printf("file not found\n");
return 1;}
fseek( pFile, 0, SEEK_END );
iFileLen = ftell( pFile );
fclose( pFile );
printf("%ld\n",iFileLen);
return 0;
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询