-
type cast or conversion?
I want to read 4 char from a file and then store them at an array so i do:
fread (&i_r_quan, sizeof (char), 4, f_ptr);
After checking these characters I need to store them in a structure as an integer.
Does the following work by type conversion or do I have to type cast i_r_quan to an integer first:
strcpy (i_r_quantity, i_r_quan [4]);
Also will a null be added to i_r_quan automatically when I read 4 characters into the array?:
CHEERS!!
-
Code:
union conversion{
char array[4];
int i;
};
Try that on for size.
Quzah.
-
> Does the following work by type conversion or do I have to type cast i_r_quan to an integer first:
No, you need to use a routine like atoi or sscanf
If i_r_quantity is an int, then
sscanf( i_r_quan, "%d", &i_r_quantity );
> Also will a null be added to i_r_quan automatically when I read 4 characters into the array
No - you need to do this bit yourself as well