My prygram goes through a string to find names between '\'-characters
The problem is, parts of the name in sTemp remains if the new name is
shorter than the old name.
code
---------------------------------------------------
char sTemp[50];
char sText[] = "THELONGESTNAME\\samantha\\gregor\\spike\\..." ; // and
so on...
....
some code
....
int i=0;
while((sText[i] != '\\'))
{
sTemp[i] = sText[i];
i++;
}
printf("Name: %s\n",sNameBuff);
// Here i want to reset the string, totally empty it.
// this dosent do it.
sNameBuff == "";
// Start over again...
....
You don't show its definition or usage, but assuming
that 'sNameBuff' is a pointer to your string (or the
name of an array containing it), write:
*sNameBuff = 0;
or
sNameBuff[0] = 0;
There may indeed still exist characters in subsequent
memory locations, but because the first character
is now zero, subsequent characters are no longer part
of your string, it's "empty".
http://www.velocityreviews.com/forums/t317623-reset-a-string-empty-it-totally.html
No comments:
Post a Comment