Im using C and I am printing a prompt If the user enters pri

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.

Solution

#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;
}

I\'m using C, and I am printing a prompt. If the user enters \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site