Pointer Problem

This is a discussion on Pointer Problem within the C++ Programming forums, part of the General Programming Boards category; Whenever I try to use this code to get a segment of a string, I get an Access Violation. ptrC ...

  1. #1
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718

    Pointer Problem

    Whenever I try to use this code to get a segment of a string, I get an Access Violation. ptrC is a pointer to a position in a char array, and it is within the declared bounds of the array.

    Code:
    temp = *ptrC;
    *ptrC = '\0';
    //do stuff...
    *ptrC = temp;
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  2. #2
    People Love Me
    Join Date
    Jan 2003
    Posts
    412
    I'm not sure I understand the question entirely, but be sure to remember that strings dont need to have the '&' sign in front of them to have there address accessed/passed.
    Code:
    int * pInt = &myInt;
    
    char * pChar = myChar;
    Does that help any? (Probably not, huh?)

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    substring copy problems?
    You're dereferencing a null pointer perhaps.
    Post more code though.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Or are you trying to modify a string literal? For example, this is wrong:

    char *p = "Testing";
    *p = 'B';
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointer to pointer realloc problem
    By prakash0104 in forum C Programming
    Replies: 14
    Last Post: 04-06-2009, 09:53 PM
  2. Another pointer problem
    By mikahell in forum C++ Programming
    Replies: 21
    Last Post: 07-20-2006, 08:37 PM
  3. Pointer problem
    By mikahell in forum C++ Programming
    Replies: 5
    Last Post: 07-20-2006, 11:21 AM
  4. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 08:48 PM
  5. pointer problem
    By DMaxJ in forum C Programming
    Replies: 4
    Last Post: 06-11-2003, 01:14 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21