c求助(在线等)

来源:百度知道 编辑:UC知道 时间:2024/05/20 06:02:58
帮忙看一下下面的程序(其中涉及链表的循环):
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#define LEN sizeof(struct Joseph)

struct Joseph
{
int num;
int code;
struct Joseph *next;
};

struct Joseph *head;
int m,n;
int main()
{
struct Joseph * array1(void);
void array2();
array1();
array2();
system("pause");
return 0;
}

struct Joseph * array1(void)
{
int m,n,i,j,k,r,flag,l[30];
struct Joseph *p1,*p2;head=NULL;
printf("Input the value of m(初始报数上限值):");
scanf("%d",&m);
printf("Input the value of n(人数):");
scanf("%d",&n);
p1=head;
p2=p1=(struct Joseph *) malloc(LEN);
printf("Input the code of the people have:\n");
printf("NO.:");
scanf

什么乱七八糟的程序啊?
int main()
{
struct Joseph * array1(void);
void array2();
array1();
array2();
system("pause");
return 0;
}
有这个写法的吗? void array2();能这样写的吗?
懂的人也给我解释下,谢谢

楼主....你编写的这个程序看来不能运行...
这段程序的错误多...
我大体看了一下....首先你在函数void array2()中要调用在函数struct Joseph * array1(void)中建立的表head...你的函数struct Joseph * array1(void)要有返回值...而你没有地方调用这个返回值...因此,函数struct Joseph * array1(void)调用结束后head的值没有改变....第二个函数中的head的值还是空的....要想改变这种情况..你可以这样写声明函数void array1(struct Joseph ** head),然后在主函数中调用array2();之前调用array1(& head).这样head的值就能改变了...

因为C语言中函数调用的参数一般是按照值传送的方式的...也就是说你的形参的值不能改变实参的值...用指针之后调用函数加个&表示按地址传送,这样之后就能改变实参的值.

先就说这个了.还没细看程序....