GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 30-Apr-2009, 10:33
pappy3223 pappy3223 is offline
New Member
 
Join Date: Apr 2009
Posts: 1
pappy3223 is on a distinguished road

Insert one string of characters into another string


hello, i'm having problems writing a function for this scripit.

CPP / C++ / C Code:
void vowels(char string[])
{
       int i = 0;
        char c;
       while ((c = string[i++]) != '\0')
          switch(c)
          {
                 Case 'a':
                 case  'e':
                 case 'i':
                 case 'o':
                 case 'u':
             cout << c;
}  //end of switch
cout << endl;

return;
}

It asks to write af unction call addchar () to insert one string of characters into another string. The function should take three arguments: the string to be inserted, the original string, and the position in the original string where the insertion should begin. For example, the addchar("for all", message, 6) should insert the characters for all in message starting at message[5]
Last edited by LuciWiz : 30-Apr-2009 at 10:51. Reason: Please insert your C++ code between [cpp] & [/cpp] tags
  #2  
Old 30-Apr-2009, 11:03
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 713
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: New to C++


CPP / C++ / C Code:
void Insert( char* StringToBeInserted, char* OriginalString, int InsertionPosition)
{
  int i;

  // Make a buffer for building the new string
  char* buffer = new char[strlen(StringToBeInserted) + strlen(OriginalString) + 1];
  
  // put the first part of the OriginalString into the buffer
  for(i=0;i<InsertionPosition;++i) buffer[i] = OriginalString[i];

  // put the StringToBeInserted into the buffer now
  for(i=0;i<strlen(StringToBeInserted);++i) buffer[i + InsertionPosition] = StringToBeInserted[i];

  // put the last part of the OriginalString into the buffer
  // YOU CAN DO THIS PART

  // put the null terminator on the end of the string
  buffer[strlen(StringToBeInserted) + strlen(OriginalString)] = '\0';

  // copy the buffer back to the OriginalString
  // YOU CAN DO THIS PART

  // delete the buffer
  delete[] buffer;
}
 
 

Recent GIDBlogToyota - 2009 May Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 19:38.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.