You don't need/want to use atoi() on a single character. You'd simply take the value of the char variable:
Code:
#include <stdio.h>
int main(void)
{
char word[] = "total";
int i;
for (i = 0; i < sizeof word - 1; i++)
{
printf("%c %d\n", word[i], word[i]);
}
return 0;
}
My output:
Code:
t 116
o 111
t 116
a 97
l 108
As for your "hash table", you are not really implementing a hash table, you just need an array to store all possible character values, so something like:
Code:
#include <limits.h>
int count[CHAR_MAX + 1]; /* but see footnote */
You can then iterate through the string like my for loop above, increasing count[value] each time. Then you can iterate through the string again, finding the first character where count[value] is still 1.
Footnote:
Most systems you encouter will likely have a CHAR_MAX of 127 and a CHAR_MIN of -128, which denotes that a char on that system can be between -128 and 127. These values don't matter, but the point is that CHAR_MIN can (and often will) be negative.
Therefore you have to be careful you do not end up trying to access count[negative_number]. One simple approach is to check that it's >= 0 before assignging it to your count array and ignore characters that fall outside.
A more thorough approach would be to declare your array instead as:
Code:
int count[CHAR_MAX - CHAR_MIN + 1];
And then use an offset when you assign to make sure your result is always in range:
Code:
count[value - CHAR_MIN]++;
instead of just:
Of course, another solution is just to explicitly use an unsigned char instead.