C语言问题 没有错误,但是运行就自动关闭

来源:百度知道 编辑:UC知道 时间:2024/05/21 16:05:34
我编的是一个解决约瑟夫问题的 程序
我现在没时间,具体题目及注释来不及说了,原程序如下:

#include <stdio.h>
#include <malloc.h>
#define N 10
#define S 3
#define M 4
typedef struct node
{
int data;
struct node *next;
}round;

round *h;

round *creat()
{
round *p,*t;
int i;
h=(round*)malloc(sizeof(round));
h->next=NULL;
t=h;
for(i=1;i<=N;i++)
{
p=(round*)malloc(sizeof(round));
p->data=i;
p->next=NULL;
t->next=p;
t=p;
}
p->next=h->next;
p=h->next;
for(i=0;i<N;i++)
{
printf(" %d",p->data);
p=p->next;
}
printf("\n");
return(h);
}
round *new()
{
round *p,*q;
int i,n=0,a[N];
p=(round*)malloc(sizeof(round));
p->next=NULL;
p=h->next;
for(i=1;i<S;i++) p=p->next;
while(h-&g

那是因为程序运行完了出现屏幕一下子就消失了,对于这种问题你可以让屏幕暂停一下,你就可以看到结果了。
在C里可以用一个getchar(),只有在你任意敲一下键盘上的一键后程序才开始继续执行;也可以用一个调用操作系统里的函数system("pause")
你试一下嘛,比如说你的这段程序的话就在主函数的new();下面加一个getchar();就行了

子程序 new 必须有送返值。
因为它是 round 型的。