Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - What is the function for clearing strings in C language?
What is the function for clearing strings in C language?

Method 1: Use the runtime library function memset():

memset(str, 0, sizeof(str));

Method 2: Use the Windows API Function ZeroMemory():

ZeroMemory(str, sizeof(str));

But it cannot be used for pointers.

In the case of pointers, it must be like this:

struct mystr {.....} *p;

...

memset(p, 0, sizeof(struct mystr));

Or:

ZeroMemory(p, sizeof(struct mystr));