-
clearing a variable
hello,
i am writing a program in C. i have it like this so far:
------------------------------------
#include<stdio.h>
char *com[256];
int main()
{
[first half of prog goes here]
[i want to clear the com variable here]
[last half here]
return 0;
}
------------------------------------------
yea, so can anyone tell me how i can clear the variable? cause its currently got the string "echo hello" in it, and i want to put in "echo yes", but it turns out as "echo yeslo" so i figured if i cleared it it wouldn't do that.
thanks all!
-
> char *com[256];
Given your description, I'm pretty sure you should be using
char com[256];
> but it turns out as "echo yeslo"
Well if you did
strncpy( com, "echo yes", 8 );
that is what you would see
So just do this
strcpy( com, "echo yes" );
-
And if you wanted to simply blank out the array, this would do the trick:
Code:
memset( com, 0, sizeof(com) );
-
Or simply use a for-loop to clear the array or just a part of it, since in both cases there will be "echo " in the string.
-
thanks!
thanks alot guys, especially Deckard. i looked up the man page for memset, and it looks like a really cool function, and now my prog works :)
thanks again!