|
-
Oct 28th, 2002, 04:22 PM
#1
Thread Starter
Lively Member
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 ?
-
Oct 29th, 2002, 04:26 AM
#2
Addicted Member
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
-
Oct 29th, 2002, 07:46 AM
#3
Monday Morning Lunatic
Use itoa() to convert from const char* to int.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|