Hi, I'm programming in C, on mandrake linux. I was wondering if there's any easy way to convert a string of letters into their 'character code' (or decimal) equivalent? I know of one long way round, which would be to make a list of all of the characters and numbers equivalent to each other, then call that list for reference every time I wish to convert a character, but i'm sure it can be done another way.
Any ideas? I heard atoi() converts a string, or character into an integer, but whatever character, or string i give it, it keeps returning 0, not the decimal equivalent.Code:#include <unistd.h> #include <stdio.h> #include <stdlib.h> main(int argc, char *argv[]) { //execl("/usr/bin/konqueror", " cnn.com", (char *) 0); //define char variable for the app name. char ichar[1024] = "konqueror "; //define a char variable for the command to be converted. char arbit[40] = "dir"; //check we have 4 arguments in total. if (argc != 4) { printf("Incorrect usage!\n"); return 0; } //add argv[1] to the end of the ichar string. strcat (ichar, argv[1]); //run the command. system(ichar); //convert string to decimal. /*THE FOLLOWING DOESNT WORK char my_string[] = "a"; printf("%s = %d\n", my_string); printf ("%s\n", ichar); SO IT'S COMMENTED OUT*/ return 0; }
Any help would be much appreciated.
Thanks.
Blueprint.



LinkBack URL
About LinkBacks



