如何将struct char写入文件

时间:2016-06-13 12:59:00

标签: c

typedef struct {
    const char *name;
    const unsigned char *data;
    const unsigned int size;
} Assembly;

void test(const Assembly **assemblies);

void test(const Assembly ** assemblies)
{

    //i want to print assemblies to a txt file.
    //like this:
    //name->XXX 
    //data->DDD
    //size->YYY
}

int main()
{
    test(bundled);
    return 0;
}

我刚开始学习C,这个任务太难了。  我不知道该怎么做。 请帮帮我。谢谢!

我试着这样做: enter image description here

问题是:

对于每个char二进制数组,'144'更改为-122

'255'更改为-1。

像上面的图片一样!

如何获取数据{77,90,144,0,3,0,0,0,0,0,0,0,255,255}  并将其写入txt文件。

1 个答案:

答案 0 :(得分:0)

好吧,它是144 ..你写为unsigned char(从0到255),但它似乎你读为char(从-128到127)。 144作为无符号字符是[1001000] b。 -112,因为char是[10010000] b。 您的代码没有任何问题。