1)新建custom.h
#ifndef hello_h
#define hello_h
extern void hello();
extern void sort(int list[],int n);
#endif
2)新建func.cpp / func.c
#include <stdio.h>
#define SWAP(x,y,t)((t)=(x),(x)=(y),(y)=t)
void hello(){
printf("hello c\n");
}
void sort(int list[],int n){
int i,min,j,temp;
for(i=0;i<n-1;i++){
min=i;
for(j=i+1;j<n;j++)
if(list[j]<list[min])
min=j;
SWAP(list[min],list[i],temp);
}
}
3)新建out.cpp / out.c
#include <stdio.h>
#include <stdlib.h>
#include "hello.h"
#define MAX_SIZE 101
void sort(int[],int);
void main(void){
int i,n;
int list[MAX_SIZE];
hello();
printf("\n");
printf("input the number of numbers to generate:");
scanf("%d",&n);
if(n<1 || n>MAX_SIZE){
fprintf(stderr,"improper number of n \n");
exit(EXIT_FAILURE);
}
printf("the generate numbers:\n");
for(i=0;i<n;i++){
list[i]=rand() % 1000;
printf("%d ",list[i]);
}
sort(list,n);
printf("\nthe sorted numbers:\n");
for(i=0;i<n;i++){
printf("%d ",list[i]);
}
printf("\n");
}
4)编译——连接