Urgent!!!!!!please Help Me!

This is a discussion on Urgent!!!!!!please Help Me! within the C Programming forums, part of the General Programming Boards category; I need my my program to be able to take user input fromt he keyboard, and then check the first ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    31

    Question Urgent!!!!!!please Help Me!

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

  2. #2
    Registered User
    Join Date
    Sep 2002
    Posts
    31

    how do i do the reverse one??

    Thanx for your help, i dont know why i make things so complicated for myself, im sure with more practice ill get better, but how do i go about doing the reverse part???

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Just a thought... don't mark your threads as "urgent". If you're late on an assignment, that's your problem (maybe you're not, I don't know).

    We are here to help, but we do so in our own time, and as such, don't like to be pressured.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21