소스는 아래와 같구요. XP환경에서 사용하고 있습니다.
컴파일 하면
Turbo C++ 4.5와 Borland C++ 4.52 에서는 아래와 같은 메시지가 나옵니다.
Call to undefined function 'exit' in function main()
Call to undefined function 'rand' in function main()
그리고 Tubro C++ 3.0 dos 에서 컴파일 하려고 하면
Function 'exit' should have a prototype
Function 'rand' should have a prototype
제 생각에는 exit와 rand 함수를 인식하지 못하는 것 같은데 저 두 함수는 이미 내장된 함수가 아닌지요?
어떤 문제가 있는 것인지 그리고 해결 방법은 무엇인지 조언부탁드립니다.
#include <stdio.h>
#include <math.h>
#define MAX_SIZE 101
#define SWAP(x, y, t) ((t)=(x),(x)=(y),(y)=(t))
void sort(int [], int); /* 선택 정렬 */
void main(void)
{
int i, n;
int list[MAX_SIZE];
printf("Enter the number of numbers to generate: ");
scanf("%d",&n);
if(n < 1 || n > MAX_SIZE) {
fprintf(stderr, "Improper value of n\n");
exit(1);
}
for(i=0;i<n;i++) { /* 임의의 수 생성 */
list[i] = rand() % 1000;
printf("%d",list[i]);
}
sort(list, n);
printf("\n Sorted array:\n");
for(i=0;i<n;i++) /* 저장된 숫자를 프린트 */
printf("%d",list[i]);
printf("\n");
}
void sort(int list[], int n)
{
int i, j, min, 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[i], list[min], temp);
}
}
|