I'm reading the terminal input of characters with the getchar() function and from it I have to store the duration and the description of a task. What I'm trying to figure is how to discard the entire input once I see it is invalid. I'm trying something like this, but once I break out of the loop and return from the function, the next time I go into the main it keeps from where I was once the input was invalid. This is how I am reading the stdin and how I'm verifying it.
void processFunction() { ...declarations... while ((c = getchar()) && (!in || n != ' ') { ... statements ... if(c != ' ' && (c < '0' || c > '9') { ++invalid_token; break; } ... statements ... } if (invalid_token) { printf("invalid duration\n"); --invalid_token; return; } Now, the thing that I as, a begginer, was thinking was to run the rest of the input and discard it into a trash variable. Is this good practice? I think it's very inneficient and I would like to know another approach on how to discard an entire input once it's considered invalid.
Edit: I forgot to mention, I'm also using getchar() in the main function
Thank you so much in advance