Tag: hexdump

C编程中的Hex文件读取?

我有一个问题: 我正在编写的ac程序,其function与hex编辑器非常相似。 我想接收一个文件并查看其hex值。 例如,假设我的文本文件“helloworld.txt”只有“Hello World!”字样。 在其中,我想指定程序获取该文件,读取其hex值(同样该文件是一个简单的.txt文件,而不是二进制文件)并将其存储在一个数组中供以后使用。 这是我到目前为止: #include #include int main() { char ch, file_name[25]; FILE *fp; printf(“Enter the name of file you wish to see\n”); gets(file_name); fp = fopen(file_name,”rb”); // read binary mode if( fp == NULL ) //error checking { perror(“Error while opening the file.\n”); exit(EXIT_FAILURE); } printf(“The contents of %s file are […]

如何获取结构数据的hexdump

…. finalize(char *hdrs, sendip_data *headers[], int index, sendip_data *data, sendip_data *pack) { …….. 出于调试目的,我想要data和pack结构的hex转储,其类型为sendip_data ,这是一个非常复杂的结构。 实际上它们包含一些二进制信息,所以我不确定我的项目的输出是否正确。 因此,出于调试目的,我想将数据写入文件,以便我可以使用hexdump,如下所示 – $hexdump -C file.txt 另外因为这是一个/ w数据包的运行时生成所以我也不确定data和pack结构的长度,我认为fread / fwrite将需要..所以请给我一些建议。