Hello,
I am new to C and I am trying to read a binary file with different data types. The first data types are specified as:
HeaderVersion unsigned char 1
HeaderSize unsigned long 4
DataFormat unsigned char 1
raw_data_file_name char 80
I cant seem to make it work. I get strange results when I try to print results to screen. Any suggestions? Thanks
Code:#include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> #include <malloc.h> #include <conio.h> void main() { // declarations FILE *file_in, *file_out; char inpfile[200], name_file_out[210], raw_data_file_name[80]; unsigned char header_version[1], data_format[1]; unsigned long int header_size; printf(" Input binary file\n"); scanf("%s", &inpfile); strcpy(name_file_out, "out_"); strcat(name_file_out, inpfile); printf(" Output file with amplitude: %s\n", name_file_out); if (!(file_in = fopen (inpfile, "rb"))) { printf("\nCannot open the input file - image file\n"); exit(0); } fread(header_version, sizeof(unsigned char), 1, file_in); fread(header_size, sizeof(unsigned long int), 1, file_in); fread(data_format, sizeof(unsigned char), 1, file_in); fread(raw_data_file_name, sizeof(char), 1, file_in); printf("%c\n", header_version); printf("%li\n", header_size); printf("%c\n", data_format); printf("%c\n", raw_data_file_name); fclose(file_in); }



LinkBack URL
About LinkBacks


