每次尝试编译时都会出现错误。这可能是一些愚蠢的事情,但我无法弄清楚。这是错误: aldrbw01@timber:~/project5$ make
gcc -g -c 爬虫.c -o 爬虫.o
crawler.c:在函数“crawler”中:
crawler.c:12:错误:“*”标记之前应有“{”
make: *** [crawler.o] 错误 1
#include "crawler.h"
#include "indexPage.h"
//My Carwler
int checkIndex(char* url, char** urlArray, const int MAX_N);
int getLink(const char* srcAddr, char* link, const int maxLinkLength);
char** missionControl(const char* FILE_NAME, const int Max_N);
char** crawler(const char* FILE_NAME, const int Max_N){
char** URLs;
queryHelper **structArray = malloc(sizeof(struct *wordControl)*50);
URLs= missionControl(FILE_NAME, Max_N);
return URLs;
}
char** missionControl(const char* FILE_NAME, const int Max_N){
const int MAX_BUFFER = 1000;
int cursor = 0;
int x;
char** urlArray = malloc(sizeof(char*)*Max_N);
for(x=0; x<Max_N; x++) {
urlArray[x] = NULL;
}
FILE *file = fopen(FILE_NAME, "r");
char* url;
url = malloc(sizeof(char)*1000);
int* hoplimit;
hoplimit = malloc(sizeof(int));
char* reader;
reader = malloc(sizeof(char)*1000);
int numHops;
while(fgets(reader,MAX_BUFFER ,file ) !=NULL && cursor<Max_N) {
sscanf(reader, "%s %d", url, hoplimit);
numHops=0;
while (1) {
if (checkIndex(url, urlArray, Max_N)) {
indexMyStuff(url);
cursor++;
}
numHops++;
if(numHops<=*hoplimit && cursor<Max_N) {
if (!getLink(url,url,MAX_BUFFER)) {
break;
}
} else {
break;
}
}
}
free(url);
free(hoplimit);
free(reader);
fclose(file);
return urlArray;
}
//--------------------Header FILE for IndexPage------------------------//
#ifndef INDEX_H
#define INDEX_H
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
struct wordControl{
char** words;
int* countArry;
};
typedef struct wordControl queryHelper;
queryHelper *indexMyStuff(char* argv);
#endif
最佳答案
这是获取指向struct
的指针大小的错误语法:
sizeof(struct *wordControl)
// ^
// There should be no asterisk between struct keyword and the tag
星号位于类型名称之后,而不是位于struct
和标记之间:
sizeof(struct wordControl*)
关于c - 文件之间的结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27328127/