clear/reset char array

Sep 16, 2010 at 7:53am
how do I clear all contents in a char array

i have something like this

char echoBuffer[1024];
Socket Roster_Socket;
Roster_Socket.RosterGroups(1,echoBuffer);
Roster_Socket.RosterItems(1,echoBuffer);
Roster_Socket.RosterGroups(5,echoBuffer);

the echoBuffer is used multiple times and I would like to clear it everytime before i use it again.
Sep 16, 2010 at 8:13am
here you go:

memset(echoBuffer, 0, sizeof(echoBuffer));
Sep 16, 2010 at 8:32am
cool thanks
Sep 16, 2010 at 2:44pm
alternatively, if this array is for a c string, you only need to clear the first character:

 
echoBuffer[0] = 0;

But of course, it'd be easier+safer to just use a string:

1
2
3
string echoBuffer;

echoBuffer = "";  // to clear it 
Topic archived. No new replies allowed.