CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2006
    Location
    New Jersey
    Posts
    120

    Unhappy Pointer problems

    Hi all,

    I created a function that skips past white spaces in a string:

    Code:
     
    VOID SkipSpaces(LPSTR lpszString)
    {
     while(isspace(*lpszString))
     {
      lpszString ++;
     }
    }
    I know it works, but when I call it nothing happens:

    Code:
     
    LPSTR lpszBuffer = "	 Hello World";
      
    SkipSpaces(lpszBuffer);
     
    printf(lpszBuffer); // lpszBuffer still equals "	Hello World"
    						// it should equal "Hello World"
    I think it might be a problem with pointers:

    lpszString ++;

    Does anybody know what the problem may be?

  2. #2
    Join Date
    Jul 2005
    Location
    Germany
    Posts
    1,194

    Re: Pointer problems

    You need a pointer to a pointer:
    Code:
    VOID SkipSpaces(LPSTR* lpszString)
    {
      while(isspace((*lpszString)[0]))
      {
        ++(*lpszString);
      }
    }
    Please don't forget to rate users who helped you!

  3. #3
    Join Date
    Mar 2006
    Location
    New Jersey
    Posts
    120

    Re: Pointer problems

    Hi philkr,

    Thanks very much. That fixed it!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured