anyone know why atoi produces a segfault? I want to convert '\xFF' to 255 integer. Heres the code:
Code:printf("%d",atoi('\xFF'));
anyone know why atoi produces a segfault? I want to convert '\xFF' to 255 integer. Heres the code:
Code:printf("%d",atoi('\xFF'));
For one thing single quotes are around character, you need double quotes for string literals.
Another thing is that atoi might not be able to convert hex strings, you might try strtol.
I might be wrong.
Quoted more than 1000 times (I hope).Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
Why don't you just write it like this?
I don't see the problem, compiler will always convert octal and hexadecimal values into decimals at compile time. If you want to print values in hexadecimal format than you should use %x.Code:printf("%d",0xFF);
Code:printf("%x",0xFF);
Vanity of vanities, saith the Preacher, vanity of vanities; all is vanity.
What profit hath a man of all his labour which he taketh under the sun?
All the rivers run into the sea; yet the sea is not full; unto the place from whence the rivers come, thither they return again.
For in much wisdom is much grief: and he that increaseth knowledge increaseth sorrow.
Last edited by someprogr; 11-04-2008 at 11:22 AM.
Never mind the update to the O/P's post is what I was after.
Maybe an extra pair of parenthesis if I understand what you are after or not...
Code:if (myarray([*mystruct.myval] == '\xFF')) { ...code}
Last edited by itCbitC; 11-04-2008 at 11:36 AM.
Back-to-Basics show declaration and initialization of mystruct.
and are you comparing the array index or the value stored at myarray[255]??
That's why I cast to unsigned in my example. '\xD8' is -40 as signed, but 216 as unsigned.