簡體   English   中英

所有函數和結構均引發“隱式聲明 <function> ”在main.c中使用時的錯誤/警告

[英]All functions and structs raise “implicit declaration of <function>” errors/warnings when used in main.c

出現的錯誤:

main.c:18:12: warning: implicit declaration of function ‘get_word’ [-Wimplicit-function-declaration]
     word = get_word( &sentence ); 

main.c:18:12: warning: implicit declaration of function ‘get_word’ [-Wimplicit-function-declaration]
     word = get_word( &sentence ); 

main.c:21:49: error: request for member ‘word’ in something not a structure or union
     printf("Word in word_count_struct = %s\n",CS->word)

我的main.c:

#include "bow.h"


    int main(){
        struct word_count_struct *CS;
      char *sentence = "#The quick brown fox jumped over 23&%^24 the lazy dogs."; /* test sentence */
      char *word;  /* pointer to a word */

      printf( "sentence = \"%s\"\n", sentence );  /* show the sentence */

      while (*sentence)  /* while sentence doesn't point to the '\0' character at the end of the string */
      {
        word = get_word( &sentence );  /* this will allocate memory for a word */
        printf( "word = \"%s\"; sentence = \"%s\"\n", word, sentence );  /* print out to see what's happening */
        CS = new_word_count(word);
        printf("Word in word_count_struct = %s\n",CS->word);

        free(word);  /* free the memory that was allocated in get_word */
      }



    return 0;

我的bow.h(bow.c包含所有:

#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdio.h>

#ifdef BOW_H
#define BOW_H


struct word_count_struct 
{
    char *word;
    int count;
};

struct bag_struct 
{
    struct word_count_struct *bag;
    int bag_size;
    int total_words;
};

/* More functions */

#endif

生成文件:

bag: main.o bow.o bow.h
        gcc -Wall -ansi -pedantic main.o bow.o -o bag

bow.o: bow.c bow.h
        gcc -Wall -ansi -pedantic -c bow.c -o bow.o

main.o: main.c bow.h
        gcc -Wall -ansi -pedantic -c main.c -o main.o


clean:
        rm -i bag bow.o main.o

我完全不知道是什么導致了這些錯誤,我們將不勝感激。

您沒有#ifdef BOW_H ,因此標頭基本上為空。 更改為#ifndef

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM