I am attempting to create a C program to be used as a simple command line interpreter for a UNIX system. I use fgets() to read user input which then stores input in a buffer to be parsed. If the only user input is pushing enter, I would like to reissue the prompt. Is there a way to detect if the return key was the only key entered at the prompt? Below is a snippet of code I have tried so far:
for (;;) {
printf("$prompt$ ");
fflush(stdout);
fgets(commandBuffer, 200, stdin);
/* remove trailing newline:*/
ln = strlen(commandLine) - 1;
if(commandLine[ln] == '\n')
commandLine[ln] = '\0';
/* attempt to handle if user input is ONLY return key:*/
if(commandLine[0] == '\n')
continue;