How to write a C Program to Get User Input and Compare ?
Solution :
#include <stdio.h>
#include <string.h>
#define clear() printf("\e[1;1H\e[2J");
void How(char *name1);
int main(void){
char name[20];
clear();
printf("Hello.\n");
sleep(1);
clear();
printf("Please Enter Your Name: ");
fgets(name,sizeof(name),stdin);
clear();
int nn = strlen(name); //get length of name
name[nn - 1] = '\0'; //remove newline at end of name
How(name);
}
void How(char *name1){
char ch;
clear();
printf("Hello %s, how are you?\n", name1);
printf("\t1)Good\n\t2)Bad\n>");
scanf(" %c", &ch );
if(ch == '1'){
printf("That is good to hear %s\n",name1);
sleep(2);
}
else if(ch == '2'){
printf("Sorry to hear that %s\n",name1);
sleep(2);
}
else{
printf("Sorry, that is not an option.\n");
sleep(2);
}
}
C Program Quadratic equation
Learn More :
Input
- C Program Basic logging of user input/output
- C Program File Input & Output Example
- C Program To Input & Print More Than One Words In Single Line
- Take microphone input and send to headphones
- A small I/O bound program to copy N bytes from an input file to an output file.
- C Program That in a Given Natural Number x Insert Figure c at Position p
- Input reads in the array positions and range for random generation.
- C Program that prompts the user to input a string, (whitespaces allowed)
- C Program to Input Number by the user between 1-100
- How to Gets User Input For Height in C Programming
- DEMULTIPLEXER CO ANALOG INPUTS
- C Program to Simulation program for FCFS ( First Come First Serve )
- C Program to Input Student Details into a File For Two Subjects
- Program to Display Pie Chart Accepting User Input C Program
- Input a Number and Check if it's Palindrome or not C Program
- Input Number and Print it's Reverse C Program
- Input Number and Check if it's Armstrong C Program
- Input Number and Check if it's Even or Odd C Program
- Input Two Numbers and Print Greater Number C Program
- Input Number and Calculate Sum of it's Digits C Program
Compare
Data From User