C
Colm
Hi
I'm having a wierd problem and I was wondering if anyone else had
encountered something similar...
I have a program which reads in a 5 digit number from a file in
decimal format, converts it to an unsigned int and writes it back out
to another file... It works fine in most cases, but for some reason
for the number 10 it doesn't.
It's Windows XP using Borland C++ and the code is something like...
char cp_decimal_num[5];
int i_bytes_read=read(i_in_file_id, cp_decimal_num, 5);
if (i_bytes_read != 5)
perror ("Error reading");
unsigned int ui_output_num = atoi(cp_decimal_num);
int i_bytes_written=write(i_out_file_id, &ui_output_num, 2);
if (i_bytes_written != 2)
perror ("Error writing");
Now in most cases it reads in the five digit number, (e.g. "00100"),
converts it to an unsigned int (100), and then writes 2 bytes to the
output file (64, 00).
This works for any number except... for some reason if I try it with
the number 10, it doesn't work as expected. It reads in "00010",
converts it to 10 (I've checked this in debug), but when writes it,
where I was expecting to see...
0A 00
....there is actually 3 bytes...
0D 0A 00
Yet the i_bytes_written variable still claims to have written only 2
bytes.
Can anyone tell me what's going on here? Where's that extra 0D coming
from?
Thanks
Colm
I'm having a wierd problem and I was wondering if anyone else had
encountered something similar...
I have a program which reads in a 5 digit number from a file in
decimal format, converts it to an unsigned int and writes it back out
to another file... It works fine in most cases, but for some reason
for the number 10 it doesn't.
It's Windows XP using Borland C++ and the code is something like...
char cp_decimal_num[5];
int i_bytes_read=read(i_in_file_id, cp_decimal_num, 5);
if (i_bytes_read != 5)
perror ("Error reading");
unsigned int ui_output_num = atoi(cp_decimal_num);
int i_bytes_written=write(i_out_file_id, &ui_output_num, 2);
if (i_bytes_written != 2)
perror ("Error writing");
Now in most cases it reads in the five digit number, (e.g. "00100"),
converts it to an unsigned int (100), and then writes 2 bytes to the
output file (64, 00).
This works for any number except... for some reason if I try it with
the number 10, it doesn't work as expected. It reads in "00010",
converts it to 10 (I've checked this in debug), but when writes it,
where I was expecting to see...
0A 00
....there is actually 3 bytes...
0D 0A 00
Yet the i_bytes_written variable still claims to have written only 2
bytes.
Can anyone tell me what's going on here? Where's that extra 0D coming
from?
Thanks
Colm