lains88 2021-10-15 16:48 采纳率: 0%
浏览 27

关于约瑟夫环鲁棒性完善过程中出现的问题

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

typedef int ElemType;

typedef struct Node
{
ElemType data;
int num;
struct Node *next;
}Node,*Link;

enum Color
{
black,blue,green,lakeblue,red,purple,yellow,white,gray,
lightblue,lightgreen,lightsimplegreen,lightred,lightpurple,lightyellow,brightwhite
};

void color(const unsigned short textColor)
{
if(textColor>0 && textColor<15)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),textColor);
else
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),0);
}

bool InitList(Link &L)
{
L=(Node *)malloc(sizeof(Node));
L->data=0;
L->num=0;
L->next=L;
}

bool ListEmpty(Node *L)
{
if(L->next==L)
return true;
else
return false;
}

int Error()
{
int run();
color(red);
printf("\n最唗堤渣,潰脤蠟腔怀硉\n\n");
printf("潰聆善最唗堤渣ㄛ最唗撈蔚笭......\n\n");
Sleep(1500);
color(brightwhite);
printf(" 求求求求求求求求求求求求求求求求求求求求求求求求求\n\n");
Sleep(1000);
run();
}

bool CreateList(int n,Link &L)
{
Link p,q;
q=L;
if(ListEmpty(q)==true)
{
printf("\n甡棒怀涴%d跺腔場宎躇鎢\n",n);
printf("藩棒怀俇傖綴瑩珨棒隙陬ㄩ\n\n");
for(int i=1;i<=n;i++)
{
p=(Node *)malloc(sizeof(Node));
scanf("%d",&p->data);
p->num=i;
L->next=p;
L=p;
}
L->next=q->next;
free(q);
}
else
Error();
}

void Output(Link &L,int m,int n)
{
Link p,q;
p=L;
if(ListEmpty(q)==false)
{
color(green);
printf("\n堤蹈佼唗峈ㄩ");
for(int i=1;i<=n;i++)
{
for(int i=1;i<m;i++)
p=p->next;
q=p->next;
m=q->data;
printf("%d ",q->num);
p->next=q->next;
free(q);
}
}
else
Error();
}

void UI()
{
system("color 0F");
printf(" 埮阞痲遠\n\n");
printf("�求求求求求求求求求求求求求求求求求求求求求求求求�\n");
printf("�寞寀ㄩ晤瘍岆1ㄛ2ㄛ##n腔n跺偌桽佼奀渀源砃峓 �\n");
printf("�釴珨ㄛ藩跺硐衄珨跺躇鎢ㄗ淏淕杅ㄘ﹝珨羲宎恁�\n");
printf("�珨跺淏淕杅釬峈惆杅奻癹硉m,植菴珨跺羲宎佼奀渀 �\n");
printf("�源砃赻1羲宎佼唗惆杅ㄛ惆善m奀礿砦惆杅﹝惆m腔堤 �\n");
printf("�蹈ㄛ蔚坻腔躇鎢釬峈陔腔m硉ㄛ植坻婓佼奀渀源砃腔狟 �\n");
printf("�珨跺羲宎笭陔植1惆杅ㄛ森狟ㄛ眻善垀衄窒 �\n");
printf("�堤蹈峈砦﹝ �\n");
printf("�求求求求求求求求求求求求求求求求求求求求求求求求�\n\n");
}

int run()
{
Link L,p,q;
int m=0,n=0;
L=NULL;
UI();
InitList(L);
printf("恁寁珨跺淏淕杅釬峈惆杅奻癹硉ㄩ");
int debug1= scanf("%d",&m);
if(!debug1)
Error();
printf("\n怀軞杅ㄩ");
int debug2=scanf("%d",&n);
if(!debug2)
Error();
CreateList(n,L);
Output(L,m,n);
printf("\n");
return 0;
}

int main()
{
run();
return 0;
}

现在问题在输入一个字母例如a时,它会一直报错,进入一个死循环,求大神解答。我尝试以内存释放,函数分离等方面去想,但还是改不明白。

  • 写回答

1条回答 默认 最新

  • CSDN专家-link 2021-10-15 16:50
    关注

    你是指int debug1= scanf("%d",&m);这句时你输入的是字符a?

    评论

报告相同问题?

问题事件

  • 创建了问题 10月15日

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 MATLAB动图问题
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名