What is the best method to do this? This is my attempt, which failed by the way .
I'm trying to convert a command argument to a set of integers, eg ./program 417 causesCode:#include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX 5 int main (int argc, char *argv[]) { int i; char core[MAX]; int coreint[MAX]; strcpy (core, argv[1]); for(i =0; i < MAX-1; i++) coreint[i] = atoi(core[i]); printf("%d\n", coreint[1] + coreint[2]); return EXIT_SUCCESS; }
coreint[0] = 4
coreint[1] = 1
coreint[2] = 7
which are all integers.
Any assistance is appreciated.