Thread: Change few element from string

  1. #1
    Registered User
    Join Date
    Oct 2015
    Location
    ITS, Indonesia
    Posts
    9

    Change few element from string

    Hi all, i'm confused about how can i change a few words on a string to another words. I mean, i'm entering a sentences "CBoard cprogramming", and then i want to change the word "CBoard" into something new like "learning" etc. How can i do that? If i want to change it to "learning", then the length of the element is changing, and i'm confused with that

    ====

    SO i've read that i could use the strstr to find the string i want to replace, and then using strncpy to copy the string, but does it means that the string i want to replace must have the same length as i want to input? i mean changing "sample" to the same-sized string like "simple" or "riddle", right?
    Last edited by unsignedfajar; 11-23-2015 at 06:00 PM.

  2. #2
    Registered User
    Join Date
    Sep 2015
    Location
    Australia
    Posts
    63
    Hi..
    Let me have a crack at this.......use a pointer to that string ( char *). you can then change what is being pointed to .. ie. your string

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. change element in array
    By izhamzamli17 in forum C++ Programming
    Replies: 1
    Last Post: 12-18-2014, 12:17 AM
  2. Change one element of string pointed by char pointer
    By Ducky in forum C++ Programming
    Replies: 16
    Last Post: 02-15-2013, 09:29 PM
  3. Replies: 3
    Last Post: 03-16-2012, 04:42 AM
  4. Replies: 3
    Last Post: 01-15-2012, 06:09 AM
  5. Using a vector element as a string
    By Ducky in forum C++ Programming
    Replies: 3
    Last Post: 11-03-2009, 07:18 AM