主题:[讨论][求助] linux 下的段错误
分别写了几个函数,大家帮忙看看:
头文件:
//MaxMin.h
#define MAXARRAY 10
float MaxNumbers(float *array,int size);
void MinNumbers(float *min, float *array,int size);
=================================
//main.c
#include<stdio.h>
#include "MaxMin.h"
main ()
{
float Array[MAXARRAY];
FILE *fp;
int a,b,c;
float min = 0;
fp = fopen("data.txt","r");
for (a = 0; a < 10; ++a)
fscanf(fp,"%f",Array[a]) ;
MinNumbers(&min,Array,MAXARRAY);
printf("\nThe Max Number of these array is :%f\nThe Min Number of these array is :%f\n",MaxNumbers(Array,MAXARRAY),min);
}
==================================
//MinNumbers.c
void MinNumbers(float *min,float *array,int size)
{
int cnt;
*min = *array;
for (cnt = 0;cnt < size;cnt++)
{
if (*min > array[cnt])
{
*min = array[cnt];
}
}
}
====================================
//MaxNumbers.c
float *MaxNumbers(float *array,int size)
{
int cnt;
float *Max;
*Max = array[0];
for (cnt = 0;cnt < size;cnt++)
{
if (*Max < array[cnt])
*Max = array[cnt];
}
return Max;
}
====================================
//data.txt
9.16 8.30 4.28 23.5 23.9 100.5 98.66 77.00 10.000 5.21
=====================================
请大家帮忙看一下,我编译通过,执行时出现了:断错误的提示:
[xueyuan@localhost new]$ gcc -g main.c MaxNumbers.c MinNumbers.c MaxMin.h -o mai n
[xueyuan@localhost new]$ ./main
段错误
头文件:
//MaxMin.h
#define MAXARRAY 10
float MaxNumbers(float *array,int size);
void MinNumbers(float *min, float *array,int size);
=================================
//main.c
#include<stdio.h>
#include "MaxMin.h"
main ()
{
float Array[MAXARRAY];
FILE *fp;
int a,b,c;
float min = 0;
fp = fopen("data.txt","r");
for (a = 0; a < 10; ++a)
fscanf(fp,"%f",Array[a]) ;
MinNumbers(&min,Array,MAXARRAY);
printf("\nThe Max Number of these array is :%f\nThe Min Number of these array is :%f\n",MaxNumbers(Array,MAXARRAY),min);
}
==================================
//MinNumbers.c
void MinNumbers(float *min,float *array,int size)
{
int cnt;
*min = *array;
for (cnt = 0;cnt < size;cnt++)
{
if (*min > array[cnt])
{
*min = array[cnt];
}
}
}
====================================
//MaxNumbers.c
float *MaxNumbers(float *array,int size)
{
int cnt;
float *Max;
*Max = array[0];
for (cnt = 0;cnt < size;cnt++)
{
if (*Max < array[cnt])
*Max = array[cnt];
}
return Max;
}
====================================
//data.txt
9.16 8.30 4.28 23.5 23.9 100.5 98.66 77.00 10.000 5.21
=====================================
请大家帮忙看一下,我编译通过,执行时出现了:断错误的提示:
[xueyuan@localhost new]$ gcc -g main.c MaxNumbers.c MinNumbers.c MaxMin.h -o mai n
[xueyuan@localhost new]$ ./main
段错误