Advertisement
metalx1000

Get User Input and Compare

Dec 2nd, 2012
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.94 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #define clear() printf("\e[1;1H\e[2J");
  5.  
  6. void How(char *name1);
  7.  
  8. int main(void){
  9.     char name[20];
  10.  
  11.     clear();
  12.     printf("Hello.\n");
  13.     sleep(1);
  14.     clear();
  15.  
  16.     printf("Please Enter Your Name: ");
  17.     fgets(name,sizeof(name),stdin);
  18.    
  19.     clear();
  20.     int nn = strlen(name); //get length of name
  21.     name[nn - 1] = '\0'; //remove newline at end of name
  22.    
  23.     How(name);
  24. }
  25.  
  26. void How(char *name1){
  27.         char ch;
  28.  
  29.         clear();
  30.         printf("Hello %s, how are you?\n", name1);
  31.         printf("\t1)Good\n\t2)Bad\n>");
  32.         scanf(" %c", &ch );
  33.  
  34.         if(ch == '1'){
  35.                 printf("That is good to hear %s\n",name1);
  36.                 sleep(2);
  37.         }
  38.         else if(ch == '2'){
  39.                 printf("Sorry to hear that %s\n",name1);
  40.                 sleep(2);
  41.         }
  42.         else{
  43.                 printf("Sorry, that is not an option.\n");
  44.                 sleep(2);
  45.         }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement