为什么我不能在 vc 6.0 中使用 #include "getline.c"
或 strindex.c
?
-----test30src.c------
#include <stdio.h>
#include "getline.c"
#include "strindex.c"
#define MAXLINE 1000
char pattern[] = "ould";
int main()
{
char line[MAXLINE];
int found = 0;
while(getline(line, MAXLINE) > 0)
if(strindex(line, pattern) >= 0){
printf("%s", line);
found++;
}
return found;
}
------getline.c------
#include <stdio.h>
int getline(char s[], int lim)
{
int c, i;
i = 0;
while(--lim > 0 && (c = getchar()) != EOF && c != '\n')
s[i++] = c;
if(c=='\n')
s[i++] = c;
s[i] = '\0';
return i;
}
-----strindex.c-----
int strindex(char s[], char t[])
{
int i, j, k;
for(i = 0; s[i] != '\0'; i++){
for(j = i, k = 0; s[j] == t[k]; j++, k++)
;
if(k > 0 && t[k] == '\0')
return j;
}
return -1;
}
错误:
--------------------Configuration: test30 - Win32 Debug--------------------
Linking...
getline.obj : error LNK2005: _getline already defined in test30src.obj
strindex.obj : error LNK2005: _strindex already defined in test30src.obj
Debug/test30.exe : fatal error LNK1169: one or more multiply defined symbols found
最佳答案
您应该包含 string.h 而不是 getline.c
关于c - 在 c 中使用 '"#include"和此链接错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21304099/