Find the answer to your Linux question:
Results 1 to 4 of 4
So sorry if this is an FAQ, but I've been searching google for close to an hour and I can't find it. I have an array of characters in C ...
  1. #1
    Just Joined!
    Join Date
    Feb 2008
    Posts
    72

    removing character from a string in C

    So sorry if this is an FAQ, but I've been searching google for close to an hour and I can't find it. I have an array of characters in C (aka, a string) and I'd like to remove the first character. I know with strncpy() you can copy the first x number of characters, effectively removing the rest, but I'm kind of doing the opposite. I want to remove the first x number of characters (in this case, x would be 1) and keep the rest. Any info on how to do this would be greatly appreciated. TIA.

  2. #2
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    So why don't you do a strcpy(), with the source starting at the second character of the string and the destination starting at the first character of the string?
    --
    Bill

    Old age and treachery will overcome youth and skill.

  3. #3
    Just Joined!
    Join Date
    Feb 2008
    Posts
    72
    I didnt know you could do that. All the examples of strcpy() I found copy the whole thing. How do I specify where to start the copy?

  4. #4
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    How do I specify where to start the copy?
    If I just gave you the syntax, it would be like giving you your first hit of heroin for free. This:
    All the examples of strcpy() I found copy the whole thing.
    hints that your next step should be to learn thorougly how pointers and arrays work in C. If you don't know how that works, you will spend countless hours debugging in an environment that you don't understand. But if you do know how that works, you will instantly know the answer to your question.

    So if you google this:
    Code:
    C pointers arrays
    you will be on your way to using heroin responsibly.

    Hope this helps.
    --
    Bill

    Old age and treachery will overcome youth and skill.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...