I need to read a large Intel Hex file and based on data type, need to store the data in a string/character array to use later on. Below is the code, I am using chunk to read line from hex file, using data_type to check the data type in read line, sub to store parsed data from line and finaldata to keep adding data as I read. However the problem is size, the max character array size is 65535 (correct me if I am wrong) but my data is around 80,000 bytes (120K characters). How can I tackle this (using C language)? or it be better if I switch to C++ or C#? Thanks in advance for any help/insight you can provide.
Edit: Hex data from file looks like below: :020000040200F1 :10C00000814202D8BFF32F8F10BD441C42E8004366 I need to read this data line by line and based from data type (shown in bold, 04 in first line, 00 in second), if it's 00, parse the data from the next byte (byte after data type) and read until end except last byte (which is checksum). Then move to next line, if the data type is 00, parse the data and add it to previously read data (string concatenation), so the variable needs to store a big amount of final data (this is I where I am struggling, how to store that large amount of data in a single variable)?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
FILE *fp;
fp = fopen(*filename, "rb");
if(fp == NULL) {
perror("Unable to open file!");
exit(1);
}
char chunk[128];
char sub[128];
char finaldata[65535];
finaldata[0] = '\0';
// Store the chunks of text into a line buffer
size_t len = sizeof(chunk);
while(fgets(chunk, sizeof(chunk), fp) != NULL) {
//fputs(chunk, stdout);
int a=0;
if((chunk[7] == '0') && (chunk[8] == '0')) {
size_t length = strlen(chunk);
while (a < (length-13)) {
sub[a]=chunk[9+a];
a++;
}
}
strcat(finaldata, sub);
fputs(finaldata, stdout);
memset(sub,0,sizeof(sub));
printf("\n\n");
}
fclose(fp);
printf("\n\nMax line size: %zd\n", len);
return 0;
}