Click to See Complete Forum and Search --> : Pointer problems


Brenton S.
June 25th, 2006, 11:28 AM
Hi all,

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


VOID SkipSpaces(LPSTR lpszString)
{
while(isspace(*lpszString))
{
lpszString ++;
}
}


I know it works, but when I call it nothing happens:


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?

philkr
June 25th, 2006, 11:41 AM
You need a pointer to a pointer:

VOID SkipSpaces(LPSTR* lpszString)
{
while(isspace((*lpszString)[0]))
{
++(*lpszString);
}
}

Brenton S.
June 25th, 2006, 11:46 AM
Hi philkr,

Thanks very much. That fixed it!!! :)