Thread: AnsiNext

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    932

    AnsiNext

    I'm trying to replace the AnsiNext function, which is obsolete, by incrementing the pointer in a Charles Petzold program.
    But it keeps crashing on the pointer incrementation:
    (*pText)++;
    .

    What could be the cause?
    Code:
     
    
            static char  * pText = (char *) LockResource (hResource) ;
           iNumLines = 0 ;
    
            while (*pText != '\\' && *pText != '\0')
            {
                if (*pText == '\n')
                {
                    iNumLines++;
          
                }
    
                //pText = AnsiNext (pText) ;
                (*pText)++;
            }
            *pText = '\0' ;
    
            SetScrollRange (hScroll, SB_CTL, 0, iNumLines, FALSE) ;
            SetScrollPos   (hScroll, SB_CTL, 0, FALSE) ;
    
            return 0 ;
    Last edited by Ducky; 05-20-2018 at 09:59 AM.
    Using Windows 10 with Code Blocks and MingW.

  2. #2
    Registered User
    Join Date
    Dec 2017
    Posts
    1,633
    Try just pText++

    And there seems to be a function called CharNext which you might try.
    Last edited by john.c; 05-20-2018 at 10:09 AM.
    A little inaccuracy saves tons of explanation. - H.H. Munro

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    932
    Thanks, it's working with pText++ and CharNext too.


    Using Windows 10 with Code Blocks and MingW.

  4. #4
    Registered User Sir Galahad's Avatar
    Join Date
    Nov 2016
    Location
    The Round Table
    Posts
    277
    Quote Originally Posted by Ducky View Post
    I'm trying to replace the AnsiNext function, which is obsolete, by incrementing the pointer in a Charles Petzold program.
    But it keeps crashing on the pointer incrementation: .
    What could be the cause?
    You aren't incrementing the pointer, just the value that it points to.

    1) (*pText)++; // Returns the value, then increments the value [same as: *pText; *(++pText);]
    2) *(pText++); // Returns the value, then increments the pointer [same as: *pText; ++pText;]
    3) *pText++; // Same as #2

  5. #5
    Registered User
    Join Date
    Dec 2007
    Posts
    932
    Thank you Sir, clear explanation, helped a lot!
    Using Windows 10 with Code Blocks and MingW.

Popular pages Recent additions subscribe to a feed

Tags for this Thread