I'm trying to figure out a way I can change this program so that I could have a semi-colon ; instead of \n to indicate the end of a command, like this:
a ; b
The command is: a
The command is: b
a
The command is: a
How can I do this?
/* Read a command, skipping over leading blanks and any trailing
* characters.
*/
#include <stdio.h>
#define FLUSH while(getchar() != '\n');
#define DEBUG
/* Declare functions */
int skipBlanks(void);
int skipOverRestOfCommand(void);
int main()
{
/* Variable declarations */
int cmd;
/* Input is one character */
cmd = skipBlanks();
/* While cmd is not equal to end of file */
while (cmd != EOF)
{
/* Print output result */
printf("The command is: %c\n", cmd);
skipOverRestOfCommand();
/* Update loop */
cmd = skipBlanks();
}
} /* End main */
/* Function has no parameters */
int skipBlanks(void)
{
/* Variable declarations */
int c;
/* Return character from standard input */
c = getchar();
#ifdef FLUSH
/* While c is equal to one character */
while (c == ' ')
{
/* Return char from standard input */
c = getchar();
}
#endif
#ifdef DEBUG
printf("debug: input = '%c'\n", c);
#endif
/* Return c */
return c;
}
/* Function has no parameteres */
int skipOverRestOfCommand(void)
{
/* Variable declarations */
int c;
/* Return char as int */
c = getchar();
/* While c is a new line */
while (c != '\n')
{
/* Return char as int */
c = getchar();
}
/* Return c */
return c;
}