ShawnCoutts
Programmer
I am using the fgets() function to read from a file. I am fairly sure that this file is all stored on one line, but when I open it in notepad, its broken into several.
Anyways my problem is that on the second read from the file i am recieving this error:
"Access violation at address 7C901095 in module ntdll.dll. Write of address 400EBA70"
I am still unsure as to what is causing this error, i do know it has something to do with the code that is being executed after the read because if i comment out all that code the file is read just fine without any errors.
the code looks like this:
thanks in advance
Anyways my problem is that on the second read from the file i am recieving this error:
"Access violation at address 7C901095 in module ntdll.dll. Write of address 400EBA70"
I am still unsure as to what is causing this error, i do know it has something to do with the code that is being executed after the read because if i comment out all that code the file is read just fine without any errors.
the code looks like this:
Code:
while (fgets(in_buffer, 160, tap_file))
{
StrLCopy(record_type, in_buffer, 2);
switch_key = static_cast<AnsiString>(record_type).ToInt();
record = static_cast<AnsiString>(in_buffer);
switch (switch_key)
{
case 10:
HEADER *hrec;
hrec = (HEADER *) malloc(sizeof(HEADER));
sprintf(hrec->record_type, "%s", record.SubString(0,2));
sprintf(hrec->sender, "%s%", record.SubString(3,5));
sprintf(hrec->recipient, "%s", record.SubString(8,5));
sprintf(hrec->file_seq_num, "%s", record.SubString(13,5));
sprintf(hrec->tax_treatment, "%s", record.SubString(18,1));
for(int i = 1; i <= 8; i++)
{
sprintf(hrec->tax_rate[i-1], "%s", record.SubString(((4*i)+15),3));
}
sprintf(hrec->file_create_date, "%s", record.SubString(64,6));
sprintf(hrec->file_trans_date, "%s", record.SubString(70,6));
sprintf(hrec->trans_cutoff_time, "%s", record.SubString(76,12));
sprintf(hrec->utc_time_offset, "%s", record.SubString(88,5));
sprintf(hrec->spec_ver_num, "%s", record.SubString(93,2));
sprintf(hrec->international_access_code, "%s", record.SubString(95,12));
sprintf(hrec->country_code, "%s", record.SubString(107,8));
free(hrec);
break;
case 12:
EXCHANGE *erec;
erec = (EXCHANGE *) malloc(sizeof(EXCHANGE));
sprintf(erec->record_type, "%s", record.SubString(0,2));
for(int i = 1; i <= 10; i++)
{
int z = (i - 1) * 12;
char rate_info[12];
char temp_buff[10];
char temp_buff2[1];
sprintf(rate_info, "%s", record.SubString((3+z),1));
sprintf(temp_buff, "%s", record.SubString((4+z),10));
sprintf(temp_buff2, "%s", record.SubString((14+z),1));
strcat(rate_info,temp_buff);
strcat(rate_info,temp_buff2);
sprintf(erec->exchange_rate_table[i-1], "%s", rate_info);
}
free(erec);
break;
case 14:
case 20:
case 30:
case 90:
break;
}
x = feof(tap_file);
}
thanks in advance