Thread: Pointer Issue?

  1. #1
    Registered User
    Join Date
    Feb 2012

    Pointer Issue?

    Hi I'v been working through another tut and have hit an issue, the program compiles fine but then crashes after printing "This is a test". I'm presuming it's an issue to do with pointer's but could be wrong. Also, I know this may sound odd, but my OS system is 64 bit and I was wondering if this could effect it?
    #include <iostream>
    #include <cstring>
    using namespace std;
    int main() {
    char str[] = "This is a test";
    char *start, *end;
    int len;
    char t;
    cout << "Original: " << str << endl;
    len = strlen(str);
    start = str;
    end = &str[len-1];
    while(start < end) {
                t = *start;
                *start = *end;
                *end = t;
    cout << "Reversed str: " << str << endl;  
    return 0;
    Edit: Whoops sorry for wasting your time it should be end--. Although I am still interested to know if theirs any difference writing for 64 bit rather 32 bit.
    Last edited by asdfgtrew; 04-04-2012 at 08:11 AM. Reason: I should proof read better

  2. #2
    Registered User
    Join Date
    May 2010
    In your while loop you are incrementing end, don't you want to decrement this variable?


  3. #3
    Registered User
    Join Date
    Feb 2012
    Yh, figured that out just as you where posting. Thanks for the help though.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointer Issue
    By dhuan in forum C++ Programming
    Replies: 8
    Last Post: 07-02-2011, 11:47 PM
  2. not a pointer issue
    By ~Kyo~ in forum C++ Programming
    Replies: 45
    Last Post: 04-21-2010, 05:51 PM
  3. pointer issue
    By san_crazy in forum C Programming
    Replies: 4
    Last Post: 10-16-2008, 06:05 PM
  4. Pointer issue when looking through .txt
    By kordric in forum C++ Programming
    Replies: 1
    Last Post: 05-17-2008, 11:26 AM
  5. C++ pointer issue
    By yongzai in forum C++ Programming
    Replies: 8
    Last Post: 12-22-2006, 04:27 AM