I\'m using C, and I am printing a prompt. If the user enters \"print\", I will p
ID: 3939457 • Letter: I
Question
I'm using C, and I am printing a prompt. If the user enters "print", I will print a chart. If the user enters "quit", the program will terminate. I set up a printf statement to prompt the user ("Enter a command: ", now how do I scan the user input? I understand that I am supposed to use a character array, but how would I initialize it and then put it in the scanf function? Thank you. I'm using C, and I am printing a prompt. If the user enters "print", I will print a chart. If the user enters "quit", the program will terminate. I set up a printf statement to prompt the user ("Enter a command: ", now how do I scan the user input? I understand that I am supposed to use a character array, but how would I initialize it and then put it in the scanf function? Thank you.Explanation / Answer
#include <stdio.h>
#include<conio.h>
int main(){
char input[30];// initialising char array
printf("Enter a command:");// prompting to enter command
scanf("%s",input);// here is scanf function to scan string
printf("Entered %s",input);// printing what you have entered
// here is the sudo code
/*if(input=="print"){
printf(" print a chart");
}else if(input=="quit"){
exit(1);
}else {
printf(" Enter valid input");
}*/
getchar();
return 0;
}