Hi, how would I convert a string such as "ThisisASTRing" to an integer. I'm trying to find the key value for a hash table which has a size around 1055 spaces.
thanks,
unknown_
Hi, how would I convert a string such as "ThisisASTRing" to an integer. I'm trying to find the key value for a hash table which has a size around 1055 spaces.
thanks,
unknown_
You can't get the integer value for a string. But you can get the integer value for a character.
Example:
Code:#include<stdio.h> main() { printf("%d\n",'a'); }
You can use atoi...
int atoi ( const char * str );
atoi - C++ Reference
Or parsing it yourself wouldn't be too hard (though a waste of time IMO). Loop through each character, convert it to numerical value from char encoding (probably ASCII), multiply it by the base and accumulate it.
I suspect what unknown_ is looking for is "string hashing" or "hash function". Searching for those terms using google will provide plenty of information - albeit, like all such things on the internet, a mix of good and bad.