I'm trying to get this program to ignore leading tabs and blanks, but I just can't seem to figure out how. What can I further do to improve this program?
/* Read a command, skipping over leading blanks and any trailing
* characters.
*/
#include <stdio.h>
/* Declare functions */
int skipBlanks(void);
int skipOverRestOfCommand(void);
int main()
{
/* Variable declarations */
int cmd;
/* cmd is blank space */
cmd = skipBlanks();
/* While cmd is not equal to end of file */
while (cmd != EOF)
{
printf("The command is: %c\n", cmd);
skipOverRestOfCommand();
cmd = skipBlanks();
}
} /* End main */
/* Function has no parameters */
int skipBlanks(void)
{
/* Variable declarations */
int c;
/* Return character from standard input */
c = getchar();
/* While c is equal to a blank space */
while (c == ' ')
{
/* Return char from standard input */
c = getchar();
}
/* 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;
}