/* * Project P12 main routine * J Dean Brock, 2011 * * DO NOT MODIFY THIS FILE */ #include #include #include #include #include "parsecommand.h" #include "sparcematrix.h" int main(int argc, char** argv) { struct sparceMatrix *theMatrix ; char buff[2049] ; char command[3] ; int row, col ; theMatrix = NULL ; /* Read in the declaration */ while (fgets(buff, 2048, stdin) != NULL) { if (parseCommand(buff, command, &row, &col)==-1) { fprintf(stderr, "Bad command line: %s", buff) ; } else if (theMatrix == NULL) { if (command[0] != 'd') { fprintf(stderr, "Expecting dcl command: %s", buff) ; } else { if ((theMatrix = createSparceMatrix(row, col)) == NULL) { fprintf(stderr, "Command Failure: %s", buff) ; } } } else { if (command[0] == 'd') { fprintf(stderr, "Expecting non-dcl command: %s", buff) ; } else if (command[0] == 'i') { if (incrementValueSparceMatrix(theMatrix, row, col)==-1) { fprintf(stderr, "Command Failure: %s", buff) ; } } else if (command[0] == 'p') { if (printValueSparceMatrix(stdout, theMatrix, row, col)==-1) { fprintf(stderr, "Command Failure: %s", buff) ; } } else if (command[0] == 'r') { if (printRowSparceMatrix(stdout, theMatrix, row)==-1) { fprintf(stderr, "Command Failure: %s", buff) ; } } else { if (printColumnSparceMatrix(stdout, theMatrix, col)==-1) { fprintf(stderr, "Command Failure: %s", buff) ; } } } } return EXIT_SUCCESS ; }