/* zero is not counted as a positive number */ int getPosInt () { int value = 0; /* clear white space characters */ int ch; ch = getc(stdin); while (!isdigit(ch)) { if ('\n' == ch) /* error \n ==> no integer given */ return 0; if (!isspace(ch)) /* error non white space ==> integer not given next */ { clearToEoln(); return 0; } ch = getc(stdin); } value = ch - '0'; ch = getc(stdin); while (isdigit(ch)) { value = value * 10 + ch - '0'; ch = getc(stdin); } ungetc (ch, stdin); /* put the last read character back in input stream */ /* Integer value of 0 is an error in this program */ if (0 == value) clearToEoln(); return value; }
int main (int argc, char **argv) { char *input; token inputToken; //DEBUGGING MODE int debuggingMode = 0; int i; for(i = 1; i < argc; i++) { if(argv[i] != NULL) { if(strcmp(argv[1], "-d\n")) { debuggingMode = 1; } } } //DEBUGGING MODE printf ("Starting Expression Evaluation Program\n\n"); printf ("Enter Expression: "); inputToken = getInputToken (stdin); while (inputToken.type != QUIT) { /* check first Token on Line of input */ if(inputToken.type == HELP) { printCommands(); clearToEoln(stdin); } else if(inputToken.type == ERROR) { printf ("Invalid Input - For a list of valid commands, type ?\n"); clearToEoln(stdin); } else if(inputToken.type == EOLN) { printf ("Blank Line - Do Nothing\n"); /* blank line - do nothing */ } else { processExpression(inputToken, stdin, debuggingMode); } printf ("\nEnter Expression: "); inputToken = getInputToken (stdin); } printf ("Quitting Program\n"); return 1; }
int main (int argc, char **argv) { char *input; token inputToken; // ************START ADDITION int debug = 0; gen_parse_args( argc, argv, &debug); // ************END ADDITON printf ("Starting Expression Evaluation Program\n\n"); printf ("Enter Expression: "); inputToken = getInputToken (stdin); while (inputToken.type != QUIT) { /* check first Token on Line of input */ if(inputToken.type == HELP) { printCommands(); clearToEoln(stdin); } else if(inputToken.type == ERROR) { printf ("Invalid Input - For a list of valid commands, type ?\n"); clearToEoln(stdin); } else if(inputToken.type == EOLN) { printf ("Blank Line - Do Nothing\n"); /* blank line - do nothing */ } else { processExpression(inputToken, stdin, debug); } printf ("\nEnter Expression: "); inputToken = getInputToken (stdin); } printf ("Quitting Program\n"); return 1; }
/* Print out a list of the commands for this program */ void printCommands() { printf ("The commands for this program are:\n\n"); printf ("q - to quit the program\n"); printf ("? - to list the accepted commands\n"); printf ("a <size> <name> - to add a group to the wait list\n"); printf ("c <size> <name> - to add a call-ahead group to the wait list\n"); printf ("w <name> - to specify a call-ahead group is now waiting in the restaurant\n"); printf ("r <table-size> - to retrieve the first waiting group that can fit at the available table size\n"); printf ("l <name> - list how many groups are ahead of the named group\n"); printf ("d - display the wait list information\n"); /* clear input to End of Line */ clearToEoln(); }
int main (int argc, char **argv) { int dbug=0; char *input; int ch; list *l = lst_create(); if(argc ==2){ if(argv[1][0] == '-' && argv[1][1] == 'd'){ dbug = 1; // ./a.out -d printf("\nDebug mode activated\n"); } } printf ("Starting Restaurant Wait List Program\n\n"); printf ("Enter command: "); while ((ch = getNextNWSChar ()) != EOF) { /* check for the various commands */ if ('q' == ch) { printf ("Quitting Program\n"); return (0); } else if ('?' == ch) { printCommands(); } else if('a' == ch) { doAdd(l,dbug); } else if('c' == ch) { doCallAhead(l,dbug); } else if('w' == ch) { doWaiting(l,dbug); } else if('r' == ch) { doRetrieve(l,dbug); } else if('l' == ch) { doList(l,dbug); } else if('d' == ch) { doDisplay(l,dbug); } else { printf ("%c - in not a valid command\n", ch); printf ("For a list of valid commands, type ?\n"); clearToEoln(); } printf ("\nEnter command: "); } printf ("Quiting Program - EOF reached\n"); lst_free(l,dbug); return 1; }