Pointers

Discussion in 'Programming General' started by Swan, Jan 12, 2008.

Pointers
  1. Unread #1 - Jan 12, 2008 at 4:32 AM
  2. Swan
    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner

    Swan When They Cry...
    Retired Global Moderator

    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--;                
         }
    }
    
     
< need help with outo thing... | Windows Account Creator! >

Users viewing this thread
1 guest


 
 
Adblock breaks this site