LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   unable to resolve compilation error;./List.c:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ (http://www.linuxquestions.org/questions/programming-9/unable-to-resolve-compilation-error%3B-list-c-5-error-expected-%91%3D%92-%91-%92-%91%3B%92-%91asm%92-696097/)

amolgupta 01-09-2009 09:10 AM

unable to resolve compilation error;./List.c:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’
 
i have written a code it has a list.h and list .c files ..h has function prototypes and data structures ,type def etc.while .c file has function implementation
list.h
Code:

#ifndef _List_
#define _List_





struct _ListElement{
  void*data;
  struct _ListElement *next,*previous;
};
typedef struct _ListElement ListElement;


typedef struct{
  int listlength;
  ListElement *head,*tail;

}List;

ListElement* newListElement(void*data,ListElement* next,ListElement* previous);
List* newList();
void insertElementToList(List* l, void* data,int n/*after n links*/);
void prependToList(void *data,List*l);
void appendToList(List* l, void*data);
void** listToSortedArray(List*l,pt2CompareFunction comp,int flag)
void** listToArray(List*l);
void removeElementFromList(List *l, int n);
void freeList(List *l);

#endif

and List.c
Code:

#include <stdlib.h>
#include "PQueue.h"
#include "List.h"

ListElement* newListElement(void *data,ListElement *previous,ListElement *next){
  ListElement*e;
  e=(ListElement*)malloc(sizeof(ListElement));
  e->data=data;
  e->next=next;
  e->previous=previous;
  return  e;
}

List* newList(){
  List* l;
  l=(List*)malloc(sizeof(List));
  l->listlength;
  l->head=newListElement(NULL,NULL,NULL);
  l->tail=newListElement(NULL,NULL,NULL);
  l->head->next=l->tail;
  l->tail->previous=l->head;
  return l;
}

void insertElementToList(List* l, void* data,int n/*after n links*/){
  ListElement* Iter,*e;
  int i=0;
  Iter=l->head;
  for (i=0;i<n;i++)
    Iter=Iter->next;
  e=newListElement(data,Iter,Iter->next );
  Iter->next->previous=e;
  Iter->next=e;
  (l->listlength)++;
}

void prependToList(void *data,List*l){
  ListElement *e;
  e=newListElement(data,l->head,l->head->next);
  l->head->next->previous=l->head->next;
  l->head->next=l->head->next;
  l->listlength++;
}


void appendToList(List* l, void*data){
  ListElement *e;
  e=newListElement(data,l->head,l->head->next);
  l->tail->previous->next=e;
  l->tail->previous=e;
  l->listlength++;
}

void** listToSortedArray(List*l,pt2CompareFunction comp,int flag){
  int i;
  ListElement *iter;
  iter=l->head;
  PQueue *q= new_PQueue(l->listlength,flag,comp);
  for(i=0;i<l->listlength;i++){
    iter=iter->next;
    PQinsert_2(iter->data,iter->data,q);
  }
  void** arr=malloc(sizeof(void**)*l->listlength);
  for(i=0;i<l->listlength;i++){
    arr[i]=PQremoveRoot(q);
  }
  return arr;
}

void** listToArray(List*l)
{
  void **arr= malloc(sizeof(void**));
  int i;
  ListElement *iter;
  iter=l->head;
  for(i=0;i<l->listlength;i++){
    iter=iter->next;
    arr=iter->data;
  }
  return arr;
}

 

void removeElementFromList(List *l, int n){
 int i;
  ListElement *iter;
  iter=l->tail;
  for(i=0;i<n;i++){
    iter=iter->previous;
  }
  iter->next->previous=iter->previous;
  iter->previous->next=iter->next;
  free(iter);

 }

void freeList(List*l){
 int i;
  ListElement *iter;
  iter=l->tail;
  for(i=0;i<l->listlength;i++){
    iter=iter->previous;
    free(iter->next);
  }
  free(l->head);
  free(l->tail);
}


the error message looks like

Code:

gcc -c ./List.c
./List.c: In function ‘listToSortedArray’:
./List.c:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
./List.c:14: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
./List.c:25: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
./List.c:37: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
./List.c:46: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
./List.c:54: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
./List.c:71: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
./List.c:85: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
./List.c:98: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
./List.c:108: error: old-style parameter declarations in prototyped function definition
./List.c:108: error: expected ‘{’ at end of input

though the code is long but i am asking for a specific error


expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token



i don't even understand what this error means.

please help me out
thanks
Amol

amolgupta 01-09-2009 09:14 AM

sorry i had made a mistake in copying the code i have just corrected it
just in case if some one might have checked the older post

ErV 01-09-2009 09:28 AM

I think problem is here (list.h):
Code:

void** listToSortedArray(List*l,pt2CompareFunction comp,int flag)
void** listToArray(List*l);

";" is missing at the end of line with "listToSortedArray(...)".

amolgupta 01-09-2009 10:09 AM

thanks


All times are GMT -5. The time now is 05:57 AM.