Hey guys, First off I just want to say awesome site been very helpful.
Anyways, I'm currently running into a problem while trying to convert a command line argument to an int.
I'm running into a problem where I can't convert the data inside argv[1] to an int
example argv[1] = 21231
and it is grabbing the first data "2" representing it as an ascii code "50"
This converts to ascii (If I am correct its because its assigning a char to an int and thus takes it as an ASCII code)
This creates a runtime errorCode:int number = *(argv[1]);
TLDR: I'm trying to grab data from *argv[1] and convert it to an intCode:int number = atoi(*argv[1]);
FULL CODE
Thanks in advanceCode:#include <stdio.h> #include <string.h> int main(int argc, char *argv[]){ //Grab data from Command line arguements int length = strlen(argv[1]); int number = atoi(*argv[1]); int startBase = atoi(*argv[2]); int convertBase = atoi(*argv[3]); printf("Argument Amount: %d\n", argc-1); printf("Number to be converted: %d\n", number); printf("Base system %d\n", startBase); printf("Converting to base %d\n", convertBase); printf("Length %d\n", length); return 0; }



LinkBack URL
About LinkBacks



