0

I checked all the answers about how to declare a structure that is used in many other files but none of them works so please can you help me to fix this problem ?

#ifndef articleStruct_h
#define articleStruct_h
#include <stdio.h>
#include <stdlib.h>
/**
   /this is a struct Articl
   /param prix is a float
   / param chaine is atable of chars
*/

typedef struct Article{
    
    float prix;
    char  nom[50];
    
}Article;

#endif /* articleStruct_h */

this is : addArticle.c

#define addArticles_h
#define articleStruct_h
#include <stdio.h>
#include <stdlib.h>
#include "addArticles.h"
#include "articleStruct.h"


void add(Article * a, int n){
    int i=0;
    for (i=0;i<n;i++){
        printf(" quel est le nom de l\'article %d : ", i+1);
        fflush(stdout);
        scanf("%s",(a+i)->nom);
        printf(" quel est le prix de l\'article %d: ", i+1);
        fflush(stdout);
        scanf("%3f",(a+i)->prix);
        fflush(stdin);
    }
}

in the file.c it tells me that the "Article" is unknown and there an incomplete declaration when it comes to (a+i)->nom .

1 Answers1

1

#define addArticles_h should only be found in addArticle.h
#define articleStruct_h should only be found in articleStruct.h.

Bill Lynch
  • 80,138
  • 16
  • 128
  • 173
  • 1
    To build on this answer, when you #define articleStruct_h in the .c file *above* the #include of articleStruct_h, it will cause the preprocessor to ignore the contents of articleStruct.h when compiling the .c file and the definition of the structure will not appear to the compiler. – nicomp Sep 20 '20 at 17:45