|
-
Jun 4th, 2003, 06:39 PM
#1
Thread Starter
Frenzied Member
Test for a variable or not
Lets say I have code like this:
Code:
inline int Len(char *p_chString){int length = 0;while( *p_chString++ ) ++length; return length;}
void RTrim(char *p_chString)
{
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
char *buf;
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
if(*p_chString == 0 || *p_chString == 0x00) //If String Is Not Blank Or Errored
return;
buf = p_chString;
buf += Len(p_chString) - 1;
while (*buf == ' ' && Len(p_chString) )
*buf-- = '\0';
}
Which trims spaces from the right side of a string. Now if I use it like so it works great:
Code:
char cTemp[10];
strncpy(cTemp," t ",10);
RTrim(cTemp);
Like it should. But lets say a stupid user comes along and tries this:
Where you are not passing a variable. How can I test for that?
MSVS 6, .NET & .NET 2003 Pro
I HATE MSDN with .NET & .NET 2003!!!
Check out my sites:
http://www.filthyhands.com
http://www.techno-coding.com

-
Jun 4th, 2003, 07:44 PM
#2
Frenzied Member
You dont. Document how the function is supposed to be called. If you are really worried, make a second parameter to be a destination buffer, that should be initialized before the function is called.
Z.
-
Jun 5th, 2003, 10:19 AM
#3
Thread Starter
Frenzied Member
Thats what I plan to do, but I figured I would check. I thought maybe you could check the param to make it had a vaild memory allocation to it or some thing.
[EDIT]
YEAH POST 800!! 
Last edited by Technocrat; Jun 5th, 2003 at 10:44 AM.
MSVS 6, .NET & .NET 2003 Pro
I HATE MSDN with .NET & .NET 2003!!!
Check out my sites:
http://www.filthyhands.com
http://www.techno-coding.com

-
Jun 5th, 2003, 12:46 PM
#4
On a proper compiler it simply wouldn't be possible because "SPACE " would be of type const char * and you function expects char *.
But VC++ isn't a proper compiler...
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|