C语言两次output(a) ; 为什么输出结果不同?明显经过Creat() 函数后值就变了。结构体数组a和b的区别 ?

#define N 2
#define M 2*N
#include <stdio.h>
#include <conio.h>
struct record
{
float c;
int e;
};
float input1();
int input2();
void Creat() ;
void output (struct record A[N]);

main()
{
struct record a[N],b[N];
Creat(a) ;
output(a); /* 第一次output */
Creat(b) ;
output(a); /* 第二次output */ /* 为什么 第一次output 与 第二次output 结果不同*/
output(b);
}

float input1( )
{
float C1;
scanf("%f",&C1);
return C1;
}

int input2( )
{
int C2;
scanf("%4d",&C2);
return C2;
}

void output (struct record A[N])
{
int j ;
printf("\n\n\n A= ");
for (j=0 ;j<=N ; j++)
{
printf("%4.2fa^%d ",A[j].c , A[j].e);
if (j<N ) printf ("+") ;
}
printf("\n\n\n");
return ;
}

void Creat(struct record x[N])
{
int i ;
printf("input contant to X : \n\n");
for (i=0 ; i<=N ;i++)
{
printf(" input c : ");
x[i].c=input1( );
printf(" input e : ");
x[i].e=input2( );
}
return ;
}

void output (struct record A[N])
{
int j ;
printf("\n\n\n A= ");
for (j=0 ;j<N ; j++)//此处j<=N应修改为j<N 否则数组越界
{
printf("%4.2fa^%d ",A[j].c , A[j].e);
if (j<N-1 ) //此处j<N修改为 j<N-1
printf ("+") ;
}
printf("\n\n\n");
return ;
}

void Creat(struct record x[N])
{
int i ;
printf("input contant to X : \n\n");
for (i=0 ; i<N ;i++)//此处j<=N应修改为j<N 否则数组越界
{
printf(" input c : ");
x[i].c=input1( );
printf(" input e : ");
x[i].e=input2( );
}
return ;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-09-25
the same.