看来技术没有到位,有点不明白楼主的要求
C种的自学者
#include <stdio.h> #include <assert.h> #include <limits.h> #include <math.h> char * get_file_size(FILE * fp, char * buf) { long size; int i, j, k = 0; char * pTemp = buf; assert(!fseek(fp, 0L, SEEK_END)); assert((size = ftell(fp)) != -1); i = (int)log10((double)(size)); j = (int)pow(10.0, i); while(j) { if((i + 1 - k) % 3 == 0 && k) *pTemp++ = ','; *pTemp++ = size / j % 10 + '0'; j /= 10; k++; } *pTemp = '\0'; return 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; }