gpt4 book ai didi

c - 如果我有这样的c语言消息 ".exe has stopped working"?

转载 作者:行者123 更新时间:2023-11-30 21:26:03 25 4
gpt4 key购买 nike

我在运行程序时遇到 C 语言问题消息“x.exe 已停止工作”。例如 x 是文件的名称。我该如何修复它?

enter code here

#include <stdio.h>
#include <stdlib.h>



struct student
{
int id;
char *firs_name;
char *last_name;
char *email;
};

struct datetime
{
int date;
int time;
};
typedef struct student student;
typedef struct datetime datetime;

struct submission
{
student *stud1;
student *stud2;
datetime *dt;
};

typedef struct submission submission;

int details(submission *data, int n1, datetime due_date, int *lates);
submission *return_clear_arr(submission *data,int n1);


submission *return_clear_arr(submission *data,int n1)
{
int i,j;

for(i=0;i<n1;i++)
{
for(j=1;j<n1;j++)
{
if(data[i].stud1->id==data[j].stud1->id && data[i].stud2->id==data [j].stud2->id)
{

data[j].stud1->id=-1;
data[j].stud2->id=-1;
}
if(data[i].stud1->id==data[j].stud1->id)
{
data[j].stud1->id=-1;
}
if(data[i].stud1->id==data[j].stud2->id)
{
data[j].stud2->id=-1;
}
if(data[i].stud2->id==data[j].stud1->id)
{
data[j].stud1->id=-1;
}
if(data[i].stud2->id==data[j].stud2->id)
{
data[j].stud2->id =-1;
}
else
{
continue;
}
}

}
return data;
}

int details(submission *data, int n1, datetime due_date, int *lates)
{
int i,counter=0,counter1=0;
submission *data2;
data2=return_clear_arr(data,n1);

for(i=0;i<n1;i++)
{
if(data[i].dt->date < due_date.date)
{
if( data[i].stud1->id==-1 && data[i].stud2->id==-1)
{
continue;
}
if( data[i].stud1->id!=-1 && data[i].stud2->id==-1)
{
counter++;
}
if( data[i].stud1->id==-1 && data[i].stud2->id!=-1)
{
counter++;
}
if( data[i].stud1->id!=-1 && data[i].stud2->id!=-1)
{
counter+=2;
}
}
if(data[i].dt->date > due_date.date)
{
if( data[i].stud1->id==-1 && data[i].stud2->id==-1)
{
continue;
}
if( data[i].stud1->id!=-1 && data[i].stud2->id==-1)
{
counter1++;
}
if( data[i].stud1->id==-1 && data[i].stud2->id!=-1)
{
counter1++;
}
if( data[i].stud1->id!=-1 && data[i].stud2->id!=-1)
{
counter1+=2;
}
}
if(data[i].dt->date == due_date.date && data[i].dt->time < due_date.time)
{
if( data[i].stud1->id==-1 && data[i].stud2->id==-1)
{
continue;
}
if( data[i].stud1->id!=-1 && data[i].stud2->id==-1)
{
counter++;
}
if( data[i].stud1->id==-1 && data[i].stud2->id!=-1)
{
counter++;
}
if( data[i].stud1->id!=-1 && data[i].stud2->id!=-1)
{
counter+=2;
}
}
if(data[i].dt->date == due_date.date && data[i].dt->time > due_date.time)
{
if( data[i].stud1->id==-1 && data[i].stud2->id==-1)
{
continue;
}
if( data[i].stud1->id!=-1 && data[i].stud2->id==-1)
{
counter1++;
}
if( data[i].stud1->id==-1 && data[i].stud2->id!=-1)
{
counter1++;
}
if( data[i].stud1->id!=-1 && data[i].stud2->id!=-1)
{
counter1+=2;
}
}
}
*lates=counter1;
return counter;
}

int main()
{
int n1=6,result1;
int *lates1;
datetime due_date1={14314,1200};
submission data1[6];
submission sub1,sub2,sub3,sub4,sub5,sub6;
sub1.stud1[0].id= 23423446;
sub1.stud1[1].firs_name ="Yoram";
sub1.stud1[2].last_name= "Givon";
sub1.stud1[3].email= "yoram@gmail.com";
sub1.stud2[0].id= 823654434;
sub1.stud2[1].firs_name ="Mor";
sub1.stud2[2].last_name= "Kol";
sub1.stud2[3].email= "mor@gmail.com";
sub1.dt->date=13314;
sub1.dt->time=2000;
data1[0]=sub1;

sub2.stud1[0].id= 423423467;
sub2.stud1[1].firs_name ="Uri";
sub2.stud1[2].last_name= "Kaplan";
sub2.stud1[3].email= "uri@gmail.com";
sub2.stud2[0].id= 834654434;
sub2.stud2[1].firs_name ="Naama";
sub2.stud2[2].last_name= "Vilk";
sub2.stud2[3].email= "naama@gmail.com";
sub2.dt->date=12314;
sub2.dt->time=2000;
data1[1]=sub2;

sub3.stud1[0].id= 482634546;
sub3.stud1[1].firs_name ="Uriel";
sub3.stud1[2].last_name= "Shalom";
sub3.stud1[3].email= "uriel@gmail.com";
sub3.dt->date=14314;
sub3.dt->time=1100;
data1[2]=sub3;

sub4.stud1[0].id= 429283243;
sub4.stud1[1].firs_name ="Omer";
sub4.stud1[2].last_name= "Chen";
sub4.stud1[3].email= "omer@gmail.com";
sub4.stud2[0].id= 423654434;
sub4.stud2[1].firs_name ="Dan";
sub4.stud2[2].last_name= "Lerner";
sub4.stud2[3].email= "dan@gmail.com";
sub4.dt->date=13314;
sub4.dt->time=1000;
data1[3]=sub4;

sub5.stud1[0].id= 492381236;
sub5.stud1[1].firs_name ="Amit";
sub5.stud1[2].last_name= "Paz";
sub5.stud1[3].email= "amit@gmail.com";
sub5.dt->date=13314;
sub5.dt->time=800;
data1[4]=sub5;

sub6.stud1[0].id= 745919897;
sub6.stud1[1].firs_name ="Dikla";
sub6.stud1[2].last_name= "Gefen";
sub6.stud1[3].email= "dikla@gmail.com";
sub6.stud2[0].id= 925962312;
sub6.stud2[1].firs_name="Yaara";
sub6.stud2[2].last_name= "Shaked";
sub6.stud2[3].email= "yaara@gmail.com";
sub6.dt->date=14314;
sub6.dt->time=1159;
data1[5]=sub6;
result1=details(data1,n1,due_date1,lates1);
printf("%d",result1);
return 0;
}

嗨,我在运行程序时遇到一个 C 语言问题消息“x.exe 已停止工作”。例如 x 是文件的名称。我该如何修复它?

最佳答案

您需要花时间学习如何使用 IDE 的调试器以及如何检查代码和收到的任何编译器警告。你的问题出在 main() 中:

在这里,您创建了一堆提交结构实例:

submission sub1,sub2,sub3,sub4,sub5,sub6;

然后,你尝试做这个作业:

sub1.stud1[0].id= 23423446;

如果您查看提交声明:

struct submission
{
student *stud1;
student *stud2;
datetime *dt;
};

您将看到 Stud1 是指向学生的指针,而不是学生。所以没有为该结构分配内存。指针指向垃圾。然后,您尝试取消对指针的引用,并发生错误、段错误。您需要将其初始化为学生类型的有效内存块。这留给你作为学习练习。

关于c - 如果我有这样的c语言消息 ".exe has stopped working"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22443490/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com