JOIN
Get Time
forums  Revision History
Search My Post History  |  My Watches  |  User Settings
Forums Round Tables General Career Discussions Re: Foiled by a Div2-250! Revision History (1 edit)
Re: Foiled by a Div2-250! (response to post by Stroker_Ace)
Did they give you a compiler to work with or did you have to write the code out by hand? I got it but I had to fiddle with it for a few minutes. I definitely couldn't have written this out by hand and got it right the first time as it's pretty easy to be one off on the pointers, etc. :)

void reverse(char *abc1) {
    char c;
    char *abc2;
    
    c = strlen(abc1)-1;
    abc2 = new char(c);
    abc2 += c;
    while(*abc1 != '\0') {
      *abc2 = *abc1;
      --abc2;
      ++abc1;
    }
    ++abc2;
    cout<<"abc2="<<abc2<<endl;
    abc1 = abc2;
}
Re: Foiled by a Div2-250! (response to post by Stroker_Ace)
Did they give you a compiler to work with or did you have to write the code out by hand? I got it but I had to fiddle with it for a few minutes. I definitely couldn't have written this out by hand and got it right the first time as it's pretty easy to be one off on the pointers, etc. :)

void reverse(char *abc1) {
    char c;
    char *abc2;
    
    c = strlen(abc1)-1;
    abc2 = new char(c);
    abc2 += c;
    while(*abc1 != '\0') {
      *abc2 = *abc1;
      --abc2;
      ++abc1;
    }
    ++abc2;
    cout<<"abc2="<<abc2<<endl;
}