I need to convert an array element (char type) to a int variable.Need to know how i cast it.language is c. If any one have an idea about this please send me a reply. <email address removed per Posting Guidlines>
character variables are stored in C as byte sized integers so there is no need to cast between the types
e.g. consider this fragment of code when contains an array of char, the elements of which are printed as character using %c and decimal integer using %d
-
char ch[]={'A','B','C'};
-
int i;
-
for(i=0; i<3;i++)
-
printf("character %c integer value %d\n", ch[i], ch[i]);
when run gives
character A integer value 65
character B integer value 66
character C integer value 67
the ASCII character code for A is 65 decimal