delete an alphabet

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • xx1level1xx
    New Member
    • Nov 2006
    • 4

    delete an alphabet

    #

    Write a function named deleteS that accepts one character pointer as a parameter and returns no value. The parameter is a C string. This function must remove all of the upper and lower case 's' letters from the string. The resulting string must be a valid C string.

    Your function must declare no more than one local variable in addition to the parameter; that additional variable must be of a pointer type. Your function may not use any square brackets.

    int main()
    {
    char msg[50] = "She'll be a massless princess.";
    deleteS(msg);
    cout << msg; // prints he'll be a male prince.
    }


    Can anyone give me some hints on this? Thx

    this is how my function gonna look like.. I think...
    void deleteS(const char* str, char alpha)

    and alpha is gonna be S or s
  • xx1level1xx
    New Member
    • Nov 2006
    • 4

    #2
    ooop it should be void deleteS(char* str)

    Comment

    • xx1level1xx
      New Member
      • Nov 2006
      • 4

      #3
      I m a neophyte and this is my nonworking code:


      [void deleteS(char *str)
      {
      char* source= str;

      while(*source!= 0)
      {
      *source=*str;
      if (str!="S" ||str!="s")
      {

      source++;
      str++;
      }
      else if (str=="S"|| str== "s")
      {
      str++;
      }
      }
      }

      Comment

      • sivadhas2006
        New Member
        • Nov 2006
        • 142

        #4
        Hi,

        You can also do like this.

        Code:
        #include <iostream>
        
        using namespace std;
        
        void deleteS(char * a_pszInput, char *a_pszOutput)
        {
           char
              chTemp = '\0';;
        
           while(*a_pszInput !=0) 
           {      
              chTemp = *a_pszInput;
              if (chTemp != 'S' && chTemp!= 's')
              { 
                 *a_pszOutput = *a_pszInput;
                 a_pszOutput++;
              }
              a_pszInput++;
           }
        }
        
        
        int main()
        {
           char 
              szMsg[50] = "She'll be a massless princess.",
              szResult[50] = "\0";
        
           deleteS(szMsg, szResult);
           cout << szResult; // prints he'll be a male prince.
           return 0;
        }
        Regards,
        M.Sivadhas.

        Comment

        Working...