I am working on a terminal parser for a calculator written in C. I cannot figure out how to combine all the numbers between the operators to put them in an array.
For example, if the input (command line argument) was " 4+342 ", ideally it would be input[] = {"4", "+", "342"} .
Here is my code so far. I include <stdio.h> , <stdlib.h> and <ctype.h> .
typedef char * string; int main(int argc, char *argv[]) { string inputS = argv[1]; string input[10]; string temp; printf("%s\n", inputS); int i; int len = strlen(inputS); printf("parsed:\n"); for(i = 0; i < len; inputS++, i++) { if(isdigit(*inputS)) { printf("%c",*inputS); } else { printf("\n%c\n",*inputS); } } printf("\n"); return 0; }
If it is running with ./calc 4+5-546 , it will output:
4 + 5 - 546
So, what is the easiest way to get each line of this in your own slot?
c string char parsing arguments
Devan Buggay Dec 28 '10 at 16:34 2010-12-28 16:34
source share