I have written this piece of code here and I have linked it alright with a couple of other functions and a main and it is working no problem and compiling without warnings (I am using the gcc compiler).
I use an array of pointers (archive.products[]) as an entrance point to multiple lists of strings. I’m still at the beginning so the lists have only one node each.
The problem I’ve got is that I can’t get the function lprintf to show on screen the components of the one-node lists of strings I have created. Note that the printf located inside the push function prints alright. So I know that push is doing it’s job…
If anyone has any idea about what might I be doing wrong please drop a reply below.
Thank-you in advance!
#define line_length 61
#define max_products 10
struct terminal_list {
char terminal[line_length];
struct terminal_list *next;
}*newnode, *browser;
typedef struct terminal_list tlst;
struct hilevel_data {
char category[line_length];
tlst *products[max_products];
};
typedef struct hilevel_data hld;
void import_terms(FILE *fp, hld archive){
char buffer[line_length];
char filter_t[3] = "}\n";
int i = 0, j = 0;
while (!feof(fp)) {
fgets(buffer, line_length, fp);
if (strcmp(buffer, filter_t) == 0) {
return;
}
head_initiator(archive, i);
push(buffer,archive, i);
lprintf();
i++;
}
}
void head_initiator(hld archive, int i){
browser = NULL;
archive.products[i] = NULL;
}
void push(char buffer[],hld archive, int i){
newnode = (tlst *)malloc(sizeof(tlst));
strcpy(newnode->terminal, buffer);
// printf("%s", newnode->terminal);
archive.products[i] = browser;
newnode->next = browser;
browser = newnode;
}
void lprintf(){
tlst *p;
p = browser;
if (p = NULL){
printf("empty\n");
}
while(p!=NULL){
printf("%s\n", p->terminal);
p=p->next;
}
}
On :
void lprintf()should be