Search code examples
cmultithreadingargvargc

C taking in arguments from Command prompt as conditions


I'm completely new to C...well sort of. i kind know c++. I'm trying to run a multi-threated program for my assignment, and one of the requirements was to have the user input his commands on the command prompt. Essentially what i'm asking is, how can i set up int main so that it can constantly take inputs from the command prompt(so i can start new threads) without stopping, and how to make comparisons such as if the user presses 'E' do this, if he presses F do that and so on. I'm guessing that the argc doesnt matter at all because i don't know how many commands the user is going to enter. What would be the best way to go on about this


Solution

  • User-Interface-Thread:

    void *trd_func(void *p) {
      while (1) {
        int c = getchar();
        switch(c) {
            case 'E':
                 set_some_flag('E');
                 break;
            default: break;
        }
      }
      return 0;
    }