Reputation: 101
Having said that I've tried to solve the problem surfing the net and I've found some questions very similar to my problem, but despite this i didn't come to any solution. I would like if anynone could help me about the problem, explaining what doesn't work instead of redirect me to another blog.
Here the code:
1)file: list.h
#include "list.c"
#include "element.h"
typedef struct list_element {
element value;
struct list_element* next;
} item;
typedef item* list;
list emptyList(void);
boolean empty(list);
element head(list);
list tail(list);
list cons(element, list);
.......
#include "list.h"
#include <stdio.h>
#include <stdlib.h>
list emptyList(void) {
return NULL;
}
boolean empty(list l) {
if (l == NULL)
return true;
else
return false;
}
list tail(list l) {
if (empty(l))
return NULL;
else
return l->next;
}
....
3)file element.h
#include "element.c"
#ifndef ELEMENT_H
#define ELEMENT_H
typedef int element;
typedef enum { false, true } boolean;
boolean isLess(element, element);
boolean isEqual(element, element);
element getElement(void);
void printElement(element);
#include "element.h"
#include <stdio.h>
boolean isEqual(element e1, element e2) {
return (e1 == e2);
}
boolean isLess(element e1, element e2) {
return (e1 < e2);
}
element getElement() {
element el;
scanf(" %d", &el);
return el;
}
void printElement(element el) {
printf(" % d", el);
}
then the compiler gave me error code:
E0003(file #include /../../../../../../element.h includes itself)
and error
code C1014 (too many file of inclusion, depth=1024) for file list.c and element.c```
So I've tried to use the guards (surely in the wrong way) and the error list was almost the same.
I would be grateful if someone could help me out
thank you for the attention.
Upvotes: 0
Views: 93
Reputation: 67835
In your program you include .h file, which includes .h file, which includes the .c file ...... until you reach the compiler include depth level which is 1024 in your case.
Remove
#include "element.c"
and remove
#include "list.c"
*.h
files (header files) should not contain any data or function definitions. Those files should only have types and extern data declarations, macrodefinition, function prototypes and (when you are more advanced) static inline
functions definitions
Upvotes: 1