Results 1 to 3 of 3

Thread: String reverse function

  1. #1

    Thread Starter
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704

    String reverse function

    Hi all,

    still workin on my C++ assignment, and I need to reverse a string...

    I found a reverse function in the standard string class but I have not found anything useful on how to implement it...

    I want to simply change a string "abcd" to "dcba"

    Any help or teaching would be welcome...

  2. #2
    Addicted Member
    Join Date
    Aug 2001
    Location
    I'm mobile
    Posts
    166
    You can reverse a string by using only loops,
    for loops.......if you want more help, just tell me......
    [p r a e t o r i a n]

  3. #3
    jim mcnamara
    Guest
    Code:
    void strrev(char *in,char *out){
              char *buf;
              char *t;
              int j=0;
              int j=0;
              j=strlen(in);
              if (!j) return;
              buf = out;
              t = in;
              buf +=j + 1;
              *buf-- = '\0';
              for (i=0;i<j;i++){
                   *buf-- = *t++;
              }
    }

Posting Permissions

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



Click Here to Expand Forum to Full Width