I need my my program to be able to take user input fromt he keyboard, and then check the first letter to see if its an e. if the first letter is an e, i want the program to out put everything that came after the e.
eg input: eThis is input
output: This is input
If the first letter is a c, i want the program to count each character after the c, including white space, and output the count.
eg input: cThis is Something
output: 17
then if the first letter is a r, i want the program to reverse the input.
eg input: rThe blue dog
output: god eulb eht
If anyone can please please fix my code up to do these things i would GREATLY APPRECIATE IT!!!!!
Code:
#include <stdio.h>
#include <string.h>
/*
int do_echo(char *cmd){
char input;
scanf(cmd, "%*c %s", &input);
printf("%s", input);
}
int do_count(char *cmd){
}
int main(){
char buff[81];
while (fgets(buff, 80, stdin) != NULL){
switch(buff[0]){
case 'e':
do_echo ( buff );
return 0;
break;
/*case 'c':
do_count(buff);
return 0;
break;*//*
case 'c':
do_count(buff);
return 0;
break;
default:
printf("invalid command");
break;
}
}
return ;
}
*/
int main(){
char input[81];
while(fgets (input, 80, stdin) != NULL){
switch(input[0]){
case 'e':
echo(input);
return 0;
break;
case 'c':
count(input);
return 0;
break;
default:
printf("invalid first letter \n");
return 0;
}
}
return 0;
}
int echo(char *cmd){
char line;
scanf(cmd, "%*c %s", &line);
printf("%s \n", line);
return 0;
}
int count(char *cmd){
int count = 0;
char line[80];
scanf("%s", line);
while (line != '\0'){
count ++;
}
printf("%d", count);
return 0;
}