How would I set up a structure such that I have methods in
helper.c
main.c
main.h
... how can I include helper.c in my main.c and use the methods built in helper.c?
I am running makefile as:
all:
gcc -o main main.c
gcc -o helper helper.c
clean:
rm -f main
rm -f helper
I understand I need a helper.h, but how do I properly set that up.. say I'd like my helper file to look like this:
struct Node{
struct Node* nxt;
int x;
};
int isThere(struct Node *head, int value){
if(head==NULL){
return 0;
}
struct Node *tmp=head;
while(tmp!=NULL){
if(tmp->x==value){
return 1;
}
tmp=tmp->nxt;
}
return 0;
}
struct Node *nodeInsert(struct Node *head, int value){
if(head==NULL){
head=malloc(sizeof(struct Node));
head->x=value;
head->nxt=NULL;
printf("inserted\n");
return head;
} else if(head!=NULL && isThere(head,value)==1){
printf("duplicate\n");
return head;
} else{
struct Node *new;
struct Node *tmp=head;
while(tmp->nxt!=NULL){
tmp=tmp->nxt;
}
new=malloc(sizeof(struct Node));
new->x=value;
tmp->nxt=new;
new->nxt=NULL;
printf("inserted\n");
return head;
}}