我有一个将成为链表的结构。但起初我无法从内部结构中读取值。听起来很复杂,但这里是代码:
#include <stdio.h>
#include <stdlib.h>
struct Address
{
char city[50];
};
struct Task
{
char fullName[255];
struct Address address;
};
struct TaskList
{
struct Task* task;
struct TaskList* next;
};
struct Task createTask()
{
struct Task task;
struct Address address;
printf("Enter full name: ");
scanf("%s", task.fullName);
printf("Enter the city: ");
scanf("%s", address.city);
task.address = address;
return task;
}
void addTask(struct TaskList *head)
{
struct TaskList* temp;
struct Task task = createTask();
temp->task = &task;
temp->next = head;
head = temp;
}
int main()
{
struct TaskList *head;
head = NULL;
addTask(head);
printf("%s", head->task->address.city);
return 0;
}
当我启动应用程序并输入一些数据时,进程崩溃并显示以下代码:
进程返回 -1073741819 (0xC0000005) 执行时间:11.102 s
事实上,我应该如何处理内部结构及其领域?