• Log in or sign up for an account here: https://www.sythe.org/login

Pointers

Swan

When They Cry...
Joined
Jan 23, 2007
Sythe Gold
0
Messages
4,957
Age
32
Location
Australia
Pointers
Well, I've recently picked up a book that hasn't been touched in half a year, and started learning C++ again. As a sort of "refresher", I did some work on pointers, as they are some of the hardest things someone new will come to face.

Completed a project which reverses strings, but I'm looking for new ideas.

here is the code:

Code:
#include <iostream>
#include <cstring>

using namespace std;

void reverseString(char* str);

int main(int argc, char** argv) {
    char str[] = "This is a test";
    reverseString(str);
    cout<<str<<'\n';
    
    system("pause");
    return 0;   
}

void reverseString(char* str) {
     char *start = str, *end=&str[strlen(str)-1], t;
     
     while(start<end) {
          t = *start;
          *start = *end;
          *end = t;
          
          start++;
          end--;                
     }
}
 
Runescape Gamblingrunescape gambling
Back
Top