一个关于文件读的有关问题

一个关于文件读的问题~
从一个bin档读数据。
bin里全是1、0混搭的数据。
8位、8位相加,一直累加。。。
11111111111111110000000000000000000……
8位+8位+8位 一直加到16位
即,一个byte+一个byte一直加到word

我的想法是fread,然后放入数组中。然后类型转换,然后求和。

大家有什么好思路,一起讨论下。。。

有码更好。。。老大出的题,说40行搞定。。。我搞了一晚上光想了个思路。。。一会儿实现下。。。

求指点。。。

------解决方案--------------------
C/C++ code
#include <iostream>
#include <stdio.h>

int main()
{
    FILE *f = fopen("main.cpp", "rb");
    if (!f) {
        std::cerr << "Error: Cannot open File "<< std::endl;
        return -1;
    }
        // Get file size:
    fseek(f, 0, SEEK_END);
    const long N = ftell(f);
    fclose(f);

    f = fopen("main.cpp", "rb");
    char* buf = new char[N+1];
    fread(buf,1,N,f);
    buf[N]= '\0';

    printf("%s", buf);

    return 0;
}

------解决方案--------------------
char bin[9];
循环fscanf(f,"%8s",bin);
------解决方案--------------------
先建一个int aa[]数组,然后用fread一个字节一个字节读,放在aa数组里面,最后再对aa数组相加,因为8位+8位一直加肯定会到16位,所以用int数组
------解决方案--------------------
C/C++ code

#include <stdio.h>
#include <stdlib.h>

int main(int argc,char **argv)
{
    FILE *fp;
    unsigned short n=0;
    unsigned char s;
    fp = fopen(argv[1],"r");

    while(fread(&s,1,1,fp))
    {   
//      printf("%x ",s);
        n += (unsigned short)s;
        if(n&(1<<15)){
        printf("%d\n",n);
        n=0;
        }   
    }   
    fclose(fp);
    return 0;
}