Insert into string at specified index?

This is a discussion on Insert into string at specified index? within the C Programming forums, part of the General Programming Boards category; Using C strings is there such a way as to insert a string into another one at a specified index? ...

  1. #1
    Registered User
    Join Date
    Jun 2005
    Location
    Philadelphia
    Posts
    16

    Question Insert into string at specified index?

    Using C strings is there such a way as to insert a string into another one at a specified index? So far I have it working successfully by
    Code:
    	strcpy(CommandBuffer, "PRIVMSG ");
    	strcat(CommandBuffer, Channel);
    	strcat(CommandBuffer, " :This is some sample output\r\n");
    However, three lines seems a bit too much and I do have quite a bit of commands to add. I was wondering if there was a way to modify so the Channel string goes into the string "PRIVMSG X :This is some sample output\r\n" at X index instead of breaking this up into three seperate strings and concatenating them together. Thanks.

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Code:
    sprintf(CommandBuffer, "PRIVMSG %s :This is some sample output\r\n", Channel);
    http://www.cplusplus.com/ref/cstdio/sprintf.html

  3. #3
    Registered User
    Join Date
    Jun 2005
    Location
    Philadelphia
    Posts
    16
    Wow, that was unusually simple, and here I was looking at string.h for reference. Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 20q game problems
    By Nexus-ZERO in forum C Programming
    Replies: 24
    Last Post: 12-17-2008, 04:48 PM
  2. recursion error
    By cchallenged in forum C Programming
    Replies: 2
    Last Post: 12-18-2006, 08:15 AM
  3. Custom String class gives problem with another prog.
    By I BLcK I in forum C++ Programming
    Replies: 1
    Last Post: 12-18-2006, 02:40 AM
  4. RicBot
    By John_ in forum C++ Programming
    Replies: 8
    Last Post: 06-13-2006, 06:52 PM
  5. Replies: 4
    Last Post: 03-03-2006, 01:11 AM

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