这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 嵌入式开发 » MCU » stm32仿真问题

共2条 1/1 1 跳转至

stm32仿真问题

菜鸟
2012-11-14 12:38:43     打赏
下面程序的最后几行:
“Array_Fountion.show(Array_Fountion.name,Array_Fountion.length);
Array_Fountion.insertion_sort();
Array_Fountion.show();”,能编译通过并运行成功,想知道为什么。。。如果没有传入参数Array_Fountion.name,Array_Fountion.length,显然会报错,混乱中。。。。。
#include <stdio.h>
#include <stdlib.h>

typedef struct
{
int *name;
int length;
void (*show)();
void (*insertion_sort)();
}array;

void show_array(int *A,int A_Length)
{
int i=0;
for(i=0;i<A_Length;i++)
{
printf("%d ",A[i]);
}
printf("\n");
}

void Insertion_Sort(int A[],int n)
{
int j=0,i=0;
int key=0;
for(j=1;j<n;j++)
{
key=A[j];
i=j-1;
while(i>=0&&key<A[i])
{
A[i+1]=A[i];
i--;
}
A[i+1]=key;
}
printf("Insertion_Sort Done!\n");
}

void Initial_Array(array *string,int *Array_Int,int Array_Length)
{
string->name=Array_Int;
string->length=Array_Length;//等价于(*string).length=11;
string->show=show_array;//等价于show=&show_array
string->insertion_sort=Insertion_Sort;
}

int main()
{
int A[]={8,7,6,5,4,3,2,123,45,666};
array Array_Fountion;
Initial_Array(&Array_Fountion,A,sizeof(A)/sizeof(*A));

Array_Fountion.show(Array_Fountion.name,Array_Fountion.length);
Array_Fountion.insertion_sort();
Array_Fountion.show();
return 0;
}



关键词: stm32     仿真     问题     Array    

菜鸟
2012-11-16 17:57:07     打赏
2楼
MDK环境。。。。

共2条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]