Take the 2-minute tour ×

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) {

    head_initiator(archive, i);
    push(buffer,archive, 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("%s\n", p->terminal);
share|improve this question

2 Answers 2

up vote 1 down vote accepted

On : void lprintf()

if (p = NULL)

should be

if (p == NULL)
share|improve this answer
oh dear god thanks so much! Right under my nose! –  Eternal_Light Jan 7 '11 at 17:56
And if you'd written the much clearer if (!p) to begin with, there would never have been an issue... –  R.. Jan 7 '11 at 18:44
if (p = NULL){

I think you mean

if (p == NULL){

You're effectively emptying the list with p = NULL.

share|improve this answer
thank-you very much –  Eternal_Light Jan 7 '11 at 18:13

Your Answer


