Thread: changing the array content !!

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    19

    Post changing the array content !!

    char line1[200];

    assume that line1 array has got a string which is a set of words separated by a char say #.

    I want to find and the double occurrence of that separator and replace them by #ABC#

    and put the string back to the array line1.


    you can reply me at [email protected] also.

    thanks in advance ....
    Mehul Doshi

  2. #2
    Registered User
    Join Date
    May 2002
    Posts
    71
    u could use strtok
    and make the delimiter # and put it in a loop so that it will stop after two loops

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Originally posted by mackol
    u could use strtok
    and make the delimiter # and put it in a loop so that it will stop after two loops
    strtok() alters the contents of the array. You'd probably do better by using strchr() to find the next occurence of #. Also, use a temporary buffer to old the string as you build it.

    Just make sure that when you swap # for #ABC#, you don't exceed the length of the buffer.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 2d array question
    By gmanUK in forum C Programming
    Replies: 2
    Last Post: 04-21-2006, 12:20 PM
  2. question about multidimensional arrays
    By richdb in forum C Programming
    Replies: 22
    Last Post: 02-26-2006, 09:51 AM
  3. changing value in an array by using a function
    By nunnu in forum C Programming
    Replies: 3
    Last Post: 05-06-2004, 03:25 AM
  4. two dimensional dynamic array?
    By ichijoji in forum C++ Programming
    Replies: 6
    Last Post: 04-14-2003, 04:27 PM
  5. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM