c - 文件之间的结构

标签 c struct header-files

每次尝试编译时都会出现错误。这可能是一些愚蠢的事情,但我无法弄清楚。这是错误: 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/

相关文章:

c++ - 可以编辑 GCC 头文件吗?

c - 如何将 GtkExpander 添加到 GtkScrolledWindow 中?

无法执行系统调用 "execve"

c - 无法理解 Malloc 输出

c - 需要帮助在控制台应用程序中使用 Windows API 在 C 中创建我自己的 getch() 函数

c - C 中的链表中的链表,读取第二个列表时出现段错误

c++ - 重新审视在 C++ 中包含 C 头文件

c - 传统的 "Hello World"程序中#include<stdio.h>到底有什么用呢?

swift - 如果仅使用Protocol和Struct,如何在Swift中设计数据库模型?

json - 如何从另一个平面/简单的配置单元表中使用 map[structs] 加载配置单元表