I am trying to read a variable length record in mainframe using C programming language. But i am not able to get the desired output. Generally in COBOL when we read a VB file, the first 4 bytes constitutes the length of the record and the remaining is the data. Similarly is there any means to read the length of the record and then the data? I had attached the code below.
The issue I am facing is in C it data is read as stream and there is a last character x'15' is read at end of every line. I need to skip reading of x'15'. The catch here is my data also contains x'15' and i can't ignore all of them.
Let me know if any other information is required.
unsigned int str_len = 0;
unsigned char *str;
if ( !(fp = fopen("dd:TEST", "rb, recfm=vb, lrecl=133") ) )
printf("Error in Opening Input File\n");
fread(&str_len, 4, 1, fp);
str = calloc(str_len, sizeof(unsigned char));
fread(str, str_len, 1, fp);
printf("Data in the line %s\n", str);