I have developed my own atoi version, that converts ASCII Hex to Integer. When ASCII hex are mentioned in lowercase, code works perfectly.
If string contains uppercasase, I troed to convert it to lowercase, but code is throwing unhandled exception.
Here is the code.
It throws exception on *(p+j) = k; statement.
unsigned short my_atoi(char *p)
unsigned int i,j;
int count = 2;
i= j = 0;
while( j < count)
// If you would like to have flexibility to have both upper case
// and lower case ASCII HEX.
if ( *(p+j) >= 'A' && *(p+j) <= 'F' )
k = *(p+j)+32;
*(p+j) = k;
printf("Value of p = %d\n",k);
if ( *(p+j) >= '0' && *(p+j) <= '9' )
i = i * j * SIXTEEN + (*(p+j) - '0');
else if ( *(p+j) >= 'a' && *(p+j) <= 'f' )
i = i * j * SIXTEEN + ((*(p+j) - 'a') + 10);
I am using VC6.0 under NT environment.
It looks like, when I modify the content of pointer, it throws the exception.
Please let me know.
Code tags added by Hammer