楼主。。我常量与变量还没学懂呢。。!!!这个~~~很难啊 ~~~等我再往后学了就知道了。不过非常感谢楼主
程序代码:
#include <stdio.h> #include <assert.h> #include <limits.h> #include <math.h> char * number_format(long number, char * buf) { int i, j, k = 0; char * pTemp = buf; i = (int)log10((double)(number)); j = (int)pow(10.0, i); while(j) { if((i + 1 - k) % 3 == 0 && k) *pTemp++ = ','; *pTemp++ = number / j % 10 + '0'; j /= 10; k++; } *pTemp = '\0'; return buf; } char * get_file_size(FILE * fp, char * buf) { long size; assert(!fseek(fp, 0L, SEEK_END)); assert((size = ftell(fp)) != -1); return number_format(size, buf); } int main(void) { char buf[(int)log10((double)(LONG_MAX)) + 5]; char file_name[128]; FILE * fp; scanf("%s", file_name); assert(fp = fopen(file_name, "rb")); printf("Size of file %s is %s bytes.\n", file_name, get_file_size(fp, buf)); return 0; }
这样呢?