Guest User

Untitled

a guest
Dec 15th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. void flush_input(){
  4. int ch;
  5. while ((ch = getchar()) != 'n' && ch != EOF);
  6. }
  7.  
  8. void getinput_with_gets() {
  9. char firstname[5];
  10. char lastname[5];
  11. printf("Enter your first name:");
  12. gets(firstname);
  13. printf("Enter your last name:");
  14. gets(lastname);
  15. printf("Hello, %s, %sn", firstname, lastname);
  16. }
  17.  
  18.  
  19. void getinput_with_fgets() {
  20. char firstname[5];
  21. char lastname[5];
  22. printf("Enter your first name:");
  23. fgets(firstname, 5, stdin);
  24. printf("Enter your last name:");
  25. // fflush(stdin); // This function may not (invariably) work with input!
  26. flush_input();
  27. fgets(lastname, 5, stdin);
  28. flush_input();
  29. printf("Hello, %s, %sn", firstname, lastname);
  30. }
  31.  
  32. int main(int argc, char **argv) {
  33. getinput_with_gets();
  34. // getinput_with_fgets();
  35. return 0;
  36. }'
Add Comment
Please, Sign In to add comment