I have the following code, I want to initialize the char array to NULL.
getting the following error
error: expected an expression g_device->name1[NAME_LENGTH-1] = {'\0'};
typedef struct device_ {
uint32_t id;
char name1[NAME_LENGTH];
char name2[NAME_LENGTH];
} device_t;
device_t *g_device = NULL;
void init_device(void)
{
g_device = malloc(sizeof(device_t));
g_device->id = 0;
g_device->name1[NAME_LENGTH-1] = {'\0'};
g_device->name2[NAME_LENGTH-1] = {'\0'};
}
{'\0'}is not a valid expression in C. You probably wantg_device->name1[0] = '\0';(note, place'\0'in the beginning).