Guest User

Untitled

a guest
Aug 20th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. Press enter to continue after yes/no in C
  2. while (getchar() != 'n');
  3.  
  4. int main (int argc, const char * argv[]) {
  5. printf("Would you like to continue? Please press y or n.n");
  6.  
  7. if(getchar() == 'y'){
  8. printf("You pressed yes! Continuing...");
  9. }
  10. else{
  11. printf("Pressed no instead of yes.");
  12. }
  13. //flush commands go here
  14. printf("nPress ENTER to continue...");
  15. if(getchar()=='n'){
  16. printf("nGood work!");
  17. }else{
  18. printf("Didn't hit ENTER...");
  19.  
  20. return 0;
  21. }
  22.  
  23. 1. Single character input
  24. 2. 3 character String
  25.  
  26. #include<stdio.h>
  27. int main()
  28. {
  29. char ch[3];
  30. char c;
  31. int i=0;
  32. while(((c=getchar())!='n')){
  33. ch[i]=c;
  34. i++;
  35. }
  36. ch[i]='';
  37. if (i==1)
  38. if (ch[0]=='Y'||ch[0]=='y')
  39. printf("OK");
  40. else
  41. printf("Not OK");
  42. else if(i==3)
  43. if (strcmp(ch,"Yes")==0)
  44. printf("OK");
  45. else
  46. printf("Not OK");
  47. else
  48. printf("NOT OK");
  49. return 0;
  50. }
  51.  
  52. int c=getchar();
  53. if(c=='y' || c=='Y')
  54. ....
Add Comment
Please, Sign In to add comment