折腾了一个小时才折腾出来,在单位就是没想起来,回到家一写就想起来了。感觉基础还是不扎实。

不废话了 直接上代码:

#include <string.h>
#include <sys/stat.h>
void main()
{
char tmp[100];//定义一个用来传递的变量
const char * filename;//文件名
int ret;
struct stat file_stat_buf;//文件状态
sprintf(tmp,"/media/%d",123);// media下面有个叫123的文件
printf("%s\n",tmp);
sscanf(tmp,"%s",filename);//给const char传值
printf("%s\n",filename);
ret = stat(filename,&file_stat_buf);//此函数要求filename 必须为const char *
if(ret == -1 ) perror("stat error:");
printf("filesize:%ld",file_stat_buf.st_size);//打印文件长度
}

不知道有没有其他方式,知道的 贴出来学习一下。

Logo

更多推荐