Thread: How to select all but the first and the second character in a string?

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    52

    How to select all but the first and the second character in a string?

    Hi there,
    I have to select all the characters of a string but the first and the second one.
    I mean I have a variable called buffer like this:
    Code:
    char buffer = [03"code"];
    and I need to get a variable buffer2 == ["code"].

    Thank you in advance.

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by JOCAAN View Post
    Hi there,
    I have to select all the characters of a string but the first and the second one.
    I mean I have a variable called buffer like this:
    Code:
    char buffer = [03"code"];
    and I need to get a variable buffer2 == ["code"].

    Thank you in advance.
    strcpy(buffer2, &buffer[2]);

  3. #3
    Registered User
    Join Date
    Aug 2007
    Posts
    52
    Thank for your answer, CommonTater!
    I forgot to say that my variable is actually a pointer
    Code:
    char* buffer = [03"code"];
    so i assume the answer is now:
    Code:
    strcpy(buffer2, buffer[2]);
    right?
    I'm sorry for the inconvenience.
    Thank you.

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by JOCAAN View Post
    Thank for your answer, CommonTater!
    I forgot to say that my variable is actually a pointer
    Code:
    char* buffer = [03"code"];
    so i assume the answer is now:
    Code:
    strcpy(buffer2, buffer[2]);
    right?
    I'm sorry for the inconvenience.
    Thank you.
    No problem... I was interrupted while writing that and decided to send it "as is"... I probably shouldn't have done that... but yes, that is one way to do it. Please note from my first message, you do need the & in there for it to work.

Popular pages Recent additions subscribe to a feed