Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C程序中的一种内存错误_C_Memory_Crash_Malloc - Fatal编程技术网

C程序中的一种内存错误

C程序中的一种内存错误,c,memory,crash,malloc,C,Memory,Crash,Malloc,我使用这个结构 typedef struct { char *title; char *description; int idNumber; char* tvProducer; DateTime startTime, endTime; EventType subjects; } EmmissionType; void Emmission_read(FILE* f, EmmissionType* Emmission) { EmmissionType * temp; temp=Emmissio

我使用这个结构

typedef struct {
char *title;
char *description;
int idNumber;
char* tvProducer;
DateTime startTime, endTime;
EventType subjects;
} EmmissionType;



void Emmission_read(FILE* f, EmmissionType* Emmission) {
EmmissionType * temp;
temp=Emmission;
temp->title = (char*) malloc(sizeof(char) * 100);
...
在这里,程序崩溃,调试器返回消息

程序接收信号SIGSEGV,分段故障 下一行没关系。我改变了下一个命令,什么也没发生

编辑:

第一个参数是用于读取的打开文件指针,第二个参数是指向获取数据的变量的指针

void Top_read(FILE* f, TVNodeType head) {
TVNodeType ptr;
ptr = head;
int ekp, i;
fscanf(f, "<%d>\n", &ekp);

//Edw 3erw poses ekpompes exw kai 8a ftia3w ena struct gia tin ka8e mia
// system("pause");
Emmission_read(f, ptr->anEmmission);
ptr->next = NULL;

for (i = 1; i < ekp; i++) {
    ptr->next = mallocwarp(sizeof(TVNodeType*));

    ptr = ptr->next;

    // system("pause");
    printf("Hello\n");
    Emmission_read(f, ptr->anEmmission);
    ptr->next = NULL;
    // system("pause");
}
printf(" Top read\n");

}

listaPtr->anemission
是指针,它似乎没有初始化为指向任何有效内存

所以在这里取消引用它的值

temp->title = ...

访问
title
会引发未定义的行为。

如何调用该函数?对于
Emmission
参数,您认为如何?请编辑您的问题,以包含该信息和代码。您是否在任何地方为
一个调试
指针分配内存?您能解释一下吗
mallocwarp()
具体做什么?除了标准的
malloc()
,还有别的吗?
temp->title = ...