我正在尝试将null赋给结构中的char-name[];但是,不起作用
#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] = ' '; // error occur here
printf("%s",dir->next_entry_direction[i]->name);// error occur here;
}
return 0;
}
我无法将NULL分配给字符名称[];我该怎么修?我已经尝试过name[0]='\0',name=NULL,strcpy(name,NULL(
不能将其设置为NULL。它是一个数组,而不是指针。你能做的是:
dir->next_entry_direction[i]->name[0] = ' ';