Hi,

So, I have a file parser that, at one point, takes input of the form of "h(124) c(566) f(178)" and reads it into variable array current [7]. It will only accept l(), h(), a(), v(), c(), or f(), and stores each in a corresponding place in current. Now, I managed to make this work, but I think it could be condensed to a little less than one sixth of the code. Paraphrased:

Yeah. Literally the only thing that changes is the index of current that it writes it to. Is there any way to solve this so it's tinier, with the exact same result? Maybe putting it in a for cycle would be the first step?Code:int readstuffintovariables() { IGNOREWHITESPACE(props) if (buf == '&') { IGNOREWHITESPACE(props) if (buf == 'l') { while (buf != '(') buf = fgetc(props); for (int i = 0; i <= 2; i++) { while (num [i] != 0 || num [i] != 1 || num [i] != 2 || num [i] != 3 || num [i] != 4 || num [i] != 5 || num [i] != 6 || num [i] != 7 || num [i] != 8 || num [i] != 9) num [i] = fgetc(props); } current [0] = atoi(num); while (buf == ')') { buf = fgetc(props); } strcpy(num, "!!!"); IGNOREWHITESPACE(props) } if (buf == 'h') { while (buf != '(') buf = fgetc(props); for (int i = 0; i <= 2; i++) { while (num [i] != 0 || num [i] != 1 || num [i] != 2 || num [i] != 3 || num [i] != 4 || num [i] != 5 || num [i] != 6 || num [i] != 7 || num [i] != 8 || num [i] != 9) num [i] = fgetc(props); } current [1] = atoi(num); while (buf == ')') { buf = fgetc(props); } strcpy(num, "!!!"); IGNOREWHITESPACE(props) } if (buf == 'a') { while (buf != '(') buf = fgetc(props); for (int i = 0; i <= 2; i++) { while (num [i] != 0 || num [i] != 1 || num [i] != 2 || num [i] != 3 || num [i] != 4 || num [i] != 5 || num [i] != 6 || num [i] != 7 || num [i] != 8 || num [i] != 9) num [i] = fgetc(props); } current [2] = atoi(num); while (buf == ')') { buf = fgetc(props); } strcpy(num, "!!!"); IGNOREWHITESPACE(props) } if (buf == 'v') { while (buf != '(') buf = fgetc(props); for (int i = 0; i <= 2; i++) { while (num [i] != 0 || num [i] != 1 || num [i] != 2 || num [i] != 3 || num [i] != 4 || num [i] != 5 || num [i] != 6 || num [i] != 7 || num [i] != 8 || num [i] != 9) num [i] = fgetc(props); } current [3] = atoi(num); while (buf == ')') { buf = fgetc(props); } strcpy(num, "!!!"); IGNOREWHITESPACE(props) } if (buf == 'c') { while (buf != '(') buf = fgetc(props); for (int i = 0; i <= 2; i++) { while (num [i] != 0 || num [i] != 1 || num [i] != 2 || num [i] != 3 || num [i] != 4 || num [i] != 5 || num [i] != 6 || num [i] != 7 || num [i] != 8 || num [i] != 9) num [i] = fgetc(props); } current [4] = atoi(num); while (buf == ')') { buf = fgetc(props); } strcpy(num, "!!!"); IGNOREWHITESPACE(props) } if (buf == 'f') { while (buf != '(') buf = fgetc(props); for (int i = 0; i <= 2; i++) { while (num [i] != 0 || num [i] != 1 || num [i] != 2 || num [i] != 3 || num [i] != 4 || num [i] != 5 || num [i] != 6 || num [i] != 7 || num [i] != 8 || num [i] != 9) num [i] = fgetc(props); } current [5] = atoi(num); while (buf == ')') { buf = fgetc(props); } strcpy(num, "!!!"); IGNOREWHITESPACE(props) } else return 2; } else return 1; return 0; }