有大神能看下哪里出问题了?每次都是这样,已经打击到我的自信了。

c_program_learner 2020-11-04 02:55:15
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<unistd.h>
#include<time.h>
#define CODE 0x3b
#define MAXLEN 100
typedef struct
{
char *english;
char *chinese;
}Word;
Word word[MAXLEN];
int testType=0;
int init()
{
FILE *fp;
char fname[50];
char line[MAXLEN];
char *p;
char *word1;
char *word2;
int i=0;
int j=0;
int len;
printf("\t welcome to the words test stuition\n");
printf("============================================\n");
printf("please input the fname:");
scanf("%s",fname);
if((fp=fopen(fname,"r"))==NULL)
{
printf("opened error");
exit(0);
}
fflush(stdin);
while(fgets(line,MAXLEN,fp))
{
for(j=0;j<strlen(line);j++)
{
if(line[j]!='\n')
{
line[j]=line[j]^CODE;
}
}
p=strchr(line,'\n');
if(p!=NULL)
{
*p='\0';
}
p=strchr(line,'=');
word1=line;
word2=p;
*p='\0';
++word2;
len=strlen(word1);
word[i].english=(char*)malloc(len+1);
strcpy(word[i].english,word1);
len=strlen(word2);
word[i].chinese=(char*)malloc(len+1);
strcpy(word[i].chinese,word2);
i++;
}
fclose(fp);
return i;
}
void endtest(int size)
{
int i;
for(i=0;i<size;i++)
{
free(word[i].english);
word[i].english=NULL;
free(word[i].chinese);
word[i].chinese=NULL;
}
}
void test(int size)
{
int i,j,t;
int flag;
char choice;
int xm[4];
int count=0;
int score=0;
printf("please choice;1---chinese to eng0-----eng to chin");
scanf("%d",&testType);
fflush(stdin);

for(i=0;i<size;i++)
{
if(!testType)
{
printf("%d.english--%s--means:\n",i+1,word[i].english);
}
else
{printf("%d.chin--%s--means:\n",i+1,word[i].chinese);
}
srand(time(NULL));
count=0;
while(count<=4)
{
t=rand()%size;
if(t==i)
{
continue;
}
flag=0;
for(j=0;j<count;j++)
{
if(xm[j]==t)
{
flag=1;
}
}
if(!flag)
{
xm[count]=t;
count++;
}
}
t=rand()%4;
xm[t]=i;
if(!testType)
{
printf("\nA.%s\n",word[xm[0]].chinese);
printf("\nB.%s\n",word[xm[1]].chinese);
printf("\nC.%s\n",word[xm[2]].chinese);
printf("\nD.%s\n",word[xm[3]].chinese);
}
else
{
printf("\tA.%s\n",word[xm[0]].english);
printf("\tB.%s\n",word[xm[1]].english);
printf("\tC.%s\n",word[xm[2]].english);
printf("\tD.%s\n",word[xm[3]].english);
}
printf("please input your choice:");
choice=getchar();
fflush(stdin);
if(choice>='a'&&choice<='z')
{
choice=choice-'a'+'A';
}
if(choice-'A'==t)
{
printf("sorry,you are wromg");
score++;
}
else
{
printf("sorry,you are worng");
printf("the correct answer is:%c.\n",'A'+t);
}
getchar();
}
printf("the game is over. amoutis %d. correct is %d\n\nwelcome next time\n",size,score);
}
int main(void)
{
int size=init();
test(size);
getchar();
return 0;
}
...全文
3818 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
mouse_zhu 2020-11-05
  • 打赏
  • 举报
回复
GNU gdb (GDB) 9.2 Copyright (C) 2020 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-pc-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from aa... (gdb) r Starting program: /tmp/aa welcome to the words test stuition ============================================ please input the fname:a.c Program received signal SIGSEGV, Segmentation fault. 0x00005555555553d2 in init () at a.c:61 61 *p='\0'; (gdb) bt #0 0x00005555555553d2 in init () at a.c:61 #1 0x0000555555555975 in main () at a.c:168 (gdb) q
glen30 2020-11-04
  • 打赏
  • 举报
回复
p=strchr(line,'=');
word1=line;
word2=p;
*p='\0';

这里p为NULL(没有找到=的时候),导致崩溃的
内容概要:本文围绕“可再生能源发电与电动汽车的协同调度策略”展开硕士论文级别的研究与复现工作,基于Matlab平台构建了高比例可再生能源接入背景下电力系统与电动汽车(EV)之间的多时间尺度协同优化模型。研究重点在于应对风光发电不确定性,充分利用电动汽车作为移动储能单元的灵活充放电能力(含V2G技术),实现电网削峰填谷、提升新能源消纳效率与系统运行经济性。文中综合考虑了异质电动车集群特性、V2G过程中的损耗约束以及随机因素影响,采用如深度确定性策略梯度(DDPG)强化学习、混合整数线性规划(MILP)等先进优化算法进行求解,并通过基准模型对比验证了所提自适应调度策略在提升电网稳定性、降低运行成本方面的有效性。; 适合人群:具备一定电力系统基础知识、优化理论背景及Matlab编程能力的研究生、科研人员,以及从事新能源并网、智能电网调度、车网互动(V2G)等方向的工程技术人员。; 使用场景及目标:①学习并复现已发表高水平硕士论文中的协同调度建模方法与仿真流程;②掌握将深度强化学习(如DDPG)应用于虚拟电厂、电动汽车集群调度等复杂非线性决策问题的技术路径;③为开展新能源消纳、需求侧响应、微电网优化运行等相关课题的研究提供可复用的代码框架与创新思路参考。; 阅读建议:建议读者结合文中提供的完整Matlab代码与技术文档,深入理解模型构建逻辑、算法实现细节与参数设置依据,优先在Simulink/Matlab环境中运行并调试仿真案例,通过调整场景参数与算法超参,探究不同策略对调度效果的影响,从而深化对协同调度机制与智能优化方法应用的理解。

2,163

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 UNIX文化
社区管理员
  • UNIX文化社区
  • 文天大人
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧