|
The C Programming Language第二版中第5章第6节sort例子无法在linux下编译
出错信息如下:
/tmp/cc9i87Qf.o(.text+0xc8): In function `readlines':
: undefined reference to `alloc'
collect2: ld returned 1 exit status
好像是alloc未定义,请问怎么解决?
相关代码如下:
- #define MAXLEN 1000 /* 每个输入行的最大长度 */
- int getline(char *, int);
- char *alloc(int);
- /* readlines 函数:读取输入行 */
- int readlines(char *lineptr[], int maxlines)
- {
- int len, nlines;
- char *p, line[MAXLEN];
- nlines = 0;
- while ((len = getline(line, MAXLEN)) > 0)
- if (nlines >= maxlines || (p = alloc(len)) == NULL)
- return -1;
- else {
- line[len-1] = '\0'; /* 删除换行符 */
- strcpy(p, line);
- lineptr[nlines++] = p;
- }
- return nlines;
- }
复制代码 |
|