In C, how to I convert a string, like "0xffffff0", into an integer with the value 0xfffffff0
in other words, how do I convert a string that represents a hex number into an integer containing the value of that number?
you want algorhitm? or just use built in function or library?
convert string to char, just ffffff, i think you know how to do it, but I don't then main //blablab idk what to write here { int decimal =0 for (int index = 0; index < 6; index++) { //convert char to integer power = 5; int integer = charToInt(char[index]); decimal += pow(integer, power); power--; } printf("%d", decimal); //idk how to print } // idk how to write function in C but it takes character returns string function int charToInt(char character) { switch(character): case '0' : return 0; case '1' : return 1; ...//repeat same case 'a' : return 10 case 'b' : return 11 case 'c' : return 12 case 'd' : return 13 case 'e' : return 14 case 'f' : return 15 default : return 0 }
I just want to replace scanf with something else in this program: http://ideone.com/iK83i
sorry but i don't understand that code with weird c syntax :D
Just out of pure curiosity, why are you writing a program to read arbitrary blocks of memory. That just sounds like a potion for trouble! Ha! That said, you could replace it with gets - which will return a string from the standard in. There are lots of other options as well, I suppose. What do you need to do that scanf won't?
Gah, 10 points for forgetting a question mark at the end of my first sentence.
where's edit button? and also he does a lot weird stuff with weird c language :D
We haven't implemented an edit button yet, unfortunately. I'm going to suggest it to shadowfiend when I think to. And it's not so much weird stuff as it is interesting. He's running into a lot of interesting problems and concepts.
i think edit button was suggested bazilion times :P
It has, and we've explained the rationale for it being extremely low priority an equally large number of times.
agdgdgdgwngo, have a look at sscanf. It does the same thing as scanf, only it reads from a string instead of standard input.
what a scanf does ?
Join our real-time social learning platform and learn together with your friends!