Function execution until enter key is pressed

Viewed 714

I need a function to continue executing until the user presses the enter key, I'm thinking of something like:

do{
   function();
} while(getchar() != "\n");

but I'm not sure if that won't cause the program to wait for the user to input something before it executes the function again and unfortunately, for various reasons, I cannot just write it and quickly test it. Will this work? Is there a better way?

1 Answers
Related