<c 程序语言>第一章最后一段程序,编译报错
cc outVar.cUndefined symbols for architecture x86_64:
"_line", referenced from:
_mycopy in outVar-c483d3.o
_mygetLine in outVar-c483d3.o
"_longest", referenced from:
_main in outVar-c483d3.o
_mycopy in outVar-c483d3.o
"_max", referenced from:
_main in outVar-c483d3.o
"_mygetline", referenced from:
_main in outVar-c483d3.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
全部代码如下:
程序代码:
#include <stdio.h> #define MAXLINE 100 int mygetline(void); void mycopy(void); int main(int argc, const char *argv[]) { int len; extern int max; extern char longest[]; max = 0; while((len = mygetline()) > 0){ if(len > max){ max = len; mycopy(); } } if(max > 0) printf("%s", longest); return 0; } int mygetLine(void) { int c, i; extern char line[]; for (i = 0; i < MAXLINE-1 && (c = getchar()) != EOF && c != '\n'; i++) { line[i] = c; } if(c == '\n'){ line[i] = c; ++i; } line[i] = '\0'; return i; } void mycopy(void){ int i; extern char line[], longest[]; i = 0; while((longest[i] = line[i]) != '\0') ++i; }