Thread: Creating insert substring method?

  1. #1
    Registered User
    Join Date
    Oct 2022

    Creating insert substring method?

    I want to create a method using pointers to insert a substring within a string. I understand how to do this with arrays, but it is unclear to me how this is done using pointers. Any suggestions would be great!

  2. #2
    Registered User
    Join Date
    Oct 2022
    Hello Mate.... Here is one way of doing it

    void insert_substring(char *str, int pos, char *substr)
      if (pos > strlen(str))
        pos = strlen(str);
      int shift = strlen(substr);
      for (int i = strlen(str); i >= pos; i--)
        str[i + shift] = str[i];
      for (int i = 0; i < shift; i++)
        str[pos + i] = substr[i];
    Last edited by Salem; 10-21-2022 at 11:09 PM. Reason: Removed crayola

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Whats the proper way of creating an async method ?
    By Masterx in forum C++ Programming
    Replies: 2
    Last Post: 12-02-2020, 03:22 AM
  2. I need help with creating a substring program
    By CProgramingBegg in forum C Programming
    Replies: 9
    Last Post: 02-06-2009, 09:50 AM
  3. Recommended Method of Creating Games
    By tetsuo13 in forum Game Programming
    Replies: 17
    Last Post: 06-26-2005, 01:39 PM
  4. Replies: 3
    Last Post: 12-03-2001, 01:45 PM
  5. Replies: 1
    Last Post: 09-17-2001, 05:46 AM

Tags for this Thread