Thread: Manipulating strings

  1. #1
    Registered User
    Join Date
    Sep 2016
    Posts
    2

    Manipulating strings

    Hi,
    I'm trying to write something that adds letters to the start of a word if it starts with a certain letter.
    So far I've tried making a "for loop" and an array and in the for loop each position in the array is checked and if it's a space then the letters would be added to the position+1 (e.g if the string was Hello World array[5] would be a space so "World" would have some letters added to it).
    I think my for loop works well but I'm not sure how to implement the adding letters part as I'm not sure of the best way to move the word to the right so the letters will be able to go in front without overwriting the first letters of the word (i.e abWorld and not abrld).

    Would anyone be able to help?
    Thanks

  2. #2
    Registered User camel-man's Avatar
    Join Date
    Jan 2011
    Location
    Under the moon
    Posts
    693
    You will have to allocate more room for your string in order to overwrite the chars and add the new ones. You could either do that or create a whole new array with more room and start copying over the contents of the original string into the new string, and then add the new chars into the new string once you get to that position.,
    Code:
    int get_random_number(void)
    {
       return 4; //chosen by fair dice roll.
                 //guaranteed to be random
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. manipulating strings
    By slee8251 in forum C Programming
    Replies: 1
    Last Post: 05-02-2012, 07:50 PM
  2. Manipulating Strings? (tolower, toupper, ucfirst)
    By Atolar in forum C Programming
    Replies: 4
    Last Post: 02-10-2010, 08:00 AM
  3. Manipulating C strings
    By black_spot1984 in forum C++ Programming
    Replies: 2
    Last Post: 09-16-2008, 10:23 AM
  4. manipulating strings
    By student2005 in forum C++ Programming
    Replies: 5
    Last Post: 01-08-2004, 03:21 AM
  5. manipulating strings
    By rain_e in forum C Programming
    Replies: 14
    Last Post: 03-05-2002, 03:15 PM

Tags for this Thread