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 ...
- 05-29-2008 #1Just 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.
- 05-29-2008 #2
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.
- 05-29-2008 #3Just 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?
- 05-30-2008 #4If I just gave you the syntax, it would be like giving you your first hit of heroin for free. This:How do I specify where to start the copy?
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.All the examples of strcpy() I found copy the whole thing.
So if you google this:
you will be on your way to using heroin responsibly.Code:C pointers arrays
Hope this helps.--
Bill
Old age and treachery will overcome youth and skill.


Reply With Quote