How to do a "Press Enter to Continue" in C

2 Answers

0 votes
#include <stdio.h> 
  
int main() 
{ 
    printf("Press Enter to Continue:\n");
    
    int ch = 0;
    
    while (ch != '\n') { 
        ch = getchar(); 
    }
    
    printf("Enter pressed\n");
    
    return 0; 
}



/*
run:

Press Enter to Continue:
asjdkhdf234857#$
Enter pressed

*/

 



answered Apr 1, 2024 by avibootz
0 votes
#include <stdio.h> 
  
int main() 
{ 
    printf("Press Enter to Continue:\n");

    while (getchar() != '\n');
    
    printf("Enter pressed\n");
    
    return 0; 
}



/*
run:

Press Enter to Continue:
askjhf5678*$
Enter pressed

*/

 



answered Apr 1, 2024 by avibootz

Related questions

1 answer 263 views
3 answers 480 views
1 answer 191 views
1 answer 210 views
...