vertex format::formatLine(string line) { int size = line.length(); vertex v; //there is a ; after each number, so substr to that position, and then turn the number into normal notation from scientific size_t pos1 = line.find(";"); string doubleX = line.substr(0, pos1); v.x = formatNum(doubleX, false); //same, but substr after the first ; to the second size_t pos2 = line.rfind(";"); string doubleY = line.substr(pos1+1, pos2-pos1-1); v.y = formatNum(doubleY, false); //same, substr after second ; to end string doubleZ = line.substr(pos2+1); v.z = formatNum(doubleZ, true); return v; }
int main(int argc, char **argv) { char * operation; char * output; int * resultBinary; char * finaloutput; ArbitraryInt *firstNum; ArbitraryInt *secondNum; if (argc < 5) { fprintf(stderr, "ERROR: Too Few Arguments.\n"); return 1; } operation = argv[1]; if (operation[0] != '+' && operation [0] != '-') { fprintf(stderr, "ERROR: Unrecognized Arithmetic Operation. Please use only '+' or '-'.\n"); return 1; } firstNum = CreateInt(argv[2]); secondNum = CreateInt(argv[3]); if(firstNum->type == Invalid) { fprintf(stderr, "ERROR: Unrecognized format type for First Number. Please use 'b' for Binary, 'd' for Decimal, 'x' for Hexadecimal, or 'o' for Octal.\n"); return 1; } if(secondNum->type == Invalid) { fprintf(stderr, "ERROR: Unrecognized format type for Second Number. Please use 'b' for Binary, 'd' for Decimal, 'x' for Hexadecimal, or 'o' for Octal.\n"); return 1; } if(verifyInput(firstNum) == 1) { fprintf(stderr, "ERROR: Invalid Numerical String in First Number. Please enter a valid number for that format type.\n"); return 1; } if(verifyInput(secondNum) == 1) { fprintf(stderr, "ERROR: Invalid Numerical String in Second Number. Please enter a valid number for that format type.\n"); return 1; } output = argv[4]; if (output[0] != 'd' && output[0] != 'x' && output[0] != 'b' && output[0] != 'o') { fprintf(stderr, "ERROR: Invalid Output type. Please use 'b' for Binary, 'd' for Decimal, 'x' for Hexadecimal, or 'o' for Octal.\n"); return 1; } formatNum(firstNum); formatNum(secondNum); evenBinary(firstNum, secondNum); resultBinary = (int*) malloc((sizeof(int) * firstNum->size)); if(operation[0] == '+') add(firstNum, secondNum, resultBinary); else subtract(firstNum, secondNum, resultBinary); if (resultBinary[0] == 1) printf("%c", '-'); if(output[0] == 'o') { finaloutput = IntToOctASCII(resultBinary, firstNum->size); } else if(output[0] == 'b') { finaloutput = IntToBinASCII(resultBinary, firstNum->size); } else if(output[0] == 'x') { finaloutput = IntToHexASCII(resultBinary, firstNum->size); } else if(output[0] == 'd') { finaloutput = IntToDecASCII(resultBinary, firstNum->size); } printf(output); printf("%s\n", finaloutput); return 0; }