-
casting char to int
Hi !
I use the following to read a token :
char delimiter[] = " ";
char *token;
token = strtok( line, delimiter);
while( token != NULL ) {
printf( " %s\n", token );
token = strtok( NULL, delimiter );
}
i want to cast the toket that i read to integer and insert it to array.
anyone ?
-
Are you tokenising characters or strings? Either way you are generating strings (char arrays), and therefore casting to int would give you the pointer value (I think - correct me if I'm wrong).
If you know that the token is going to be a single char then you could use:
int num = (int)token[0];
Perhaps..?
HD
-
Use itoa() to convert from const char* to int.