Unix Systems Programming for SVR4에 나온 코드 컴파일 --?
글쓴이: ktlsu1231 / 작성시간: 일, 2004/08/08 - 11:41오후
안녕하세요.
O'Reilly의 Unix Systems Programming for SVR4에 나온 코드입니다.
컴파일이 되는 코드인가요? ^^;;
궁금해요
Solaris에서 gcc로 컴파일을 하면
bash-2.05# g++ bsort-length.c
bsort-length.c: In function `int main(int, char**)':
bsort-length.c:52: error: `exit' undeclared (first use this function)
bsort-length.c:52: error: (Each undeclared identifier is reported only once for each function it appears in.)
bash-2.05#
요렇게 나옵니다.
제가 타이핑한 것이 안되어 소스코드를 그대로 받아 실행했는데도
안되서요. 원래 안되는 코드인지 궁금합니다.
#include <string.h>
#define NSTRINGS 16 /* max. number of strings */
#define MAXLENGTH 1024 /* max. length of one string */
void bubbleSort(char **, int);
void outputLine(char *);
char *inputLine(void);
int
main(int argc, char **argv)
{
int n, nstrings;
char *p, *q, *line;
char *strptrs[NSTRINGS];
char strings[NSTRINGS][MAXLENGTH];
/*
* Read in NSTRINGS strings from the standard input.
*/
for (nstrings = 0; nstrings < NSTRINGS; nstrings++) {
/*
* Get a line from the input.
*/
if ((line = inputLine()) == NULL)
break;
/*
* Copy the line.
*/
for (p = line, q = strings[nstrings]; *p != '\0'; p++, q++)
*q = *p;
*q = '\0';
/*
* Save a pointer to the line.
*/
strptrs[nstrings] = strings[nstrings];
}
/*
* Sort the strings.
*/
bubbleSort(strptrs, nstrings);
/*
* Print the strings.
*/
for (n = 0; n < nstrings; n++)
outputLine(strptrs[n]);
exit(0);
}
/*
* bubbleSort - implementation of the basic bubble sort algorithm.
*/
void
bubbleSort(char **strings, int nstrings)
{
int i, j;
char *tmp;
int notdone;
j = nstrings;
notdone = 1;
while (notdone) {
notdone = 0;
j = j - 1;
for (i = 0; i < j; i++) {
/*
* Use strlen() to compare the strings
* by length.
*/
if (strlen(strings[i]) > strlen(strings[i+1])) {
tmp = strings[i+1];
strings[i+1] = strings[i];
strings[i] = tmp;
notdone = 1;
}
}
}
}Forums:


man 3 exitstdlib.h를 include 해보세요.
man 3 exit
stdlib.h를 include 해보세요.
----
http://nohmad.tumblr.com/
^^
감사합니다. ^^ 하지만 이렇게 나옵니다. :cry:
void outputLine(char *); char *i
void outputLine(char *);
char *inputLine(void);
위의 두 함수가 정의되지 않았습니다. 혹시 다른 파일이 따로 필요한 것 아닙니까?
[img]http://image.hanbitbook.co.kr/cover
이 책인데 소스는
http://hanbitbook.co.kr/web/example/9163/examples.tar.gz
여기 있습니다. ^^;
에궁..
Makefile 찾아서 make를 해보세요.bsort-length
Makefile 찾아서 make를 해보세요.
bsort-length.c파일만 컴파일 할때는
g++ bsort-length.c
대신 gcc -c bsort-length.c
하시면 bosrt-length.o가 생성됩니다.
bosrt-length.c파일만으로 실행파일을 만들 수 있는 경우라면
gcc bosrt-length.c하면 실행파일 a.out이 생성되겠지만
다른 파일이 필요한 경우입니다.
Makefile안에 정리가 되어있을 겁니다.
댓글 달기