[英]How to assign char[] to null inside the struct
I m trying to assign null to char name[] inside the struct;我正在尝试将 null 分配给结构内的 char name[]; however, it not working
但是,它不起作用
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#define name_size 30
#define bloc_entry_number 20
#define file_list_number 10
#define direction_list_number 10
struct File {
char name[name_size];
int block_entry[bloc_entry_number];
};
struct Direction{
char name[name_size];
int current_index;
int previous_index;
struct File* file_list[file_list_number];
int file_list_tracking[file_list_number];
struct Direction* next_entry_direction[direction_list_number];
int next_entry_direction_tracking[direction_list_number];
};
struct Block{
int index;
int size_remain;
};
int main(){
struct Direction *dir = (struct Direction*) malloc(sizeof(struct Direction));
for (int i = 0; i < 10; i ++ ){
dir->next_entry_direction[i]->name[0] = '\0'; // error occur here
printf("%s",dir->next_entry_direction[i]->name);// error occur here;
}
return 0;
}
im not able to assign NULL to char name[];我无法将 NULL 分配给 char name[]; how can i fix it?
我该如何解决? i have already try name[0] = '\0', name = NULL, strcpy(name,NULL)
我已经尝试过 name[0] = '\0', name = NULL, strcpy(name,NULL)
You cannot set it to NULL.您不能将其设置为 NULL。 It's an array and not a pointer.
它是一个数组,而不是一个指针。 What you can do is this:
你可以做的是:
dir->next_entry_direction[i]->name[0] = '\0';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.