Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to
LinuxQuestions.org , a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free.
Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please
contact us . If you need to reset your password,
click here .
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a
virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month.
Click here for more info.
01-09-2009, 09:10 AM
#1
Member
Registered: Feb 2005
Location: agra,india
Distribution: FC2
Posts: 158
Rep:
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
Last edited by amolgupta; 01-09-2009 at 09:12 AM .
01-09-2009, 09:14 AM
#2
Member
Registered: Feb 2005
Location: agra,india
Distribution: FC2
Posts: 158
Original Poster
Rep:
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
01-09-2009, 09:28 AM
#3
Senior Member
Registered: Mar 2007
Location: Russia
Distribution: Slackware 12.2
Posts: 1,202
Rep:
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(...)".
01-09-2009, 10:09 AM
#4
Member
Registered: Feb 2005
Location: agra,india
Distribution: FC2
Posts: 158
Original Poster
Rep:
thanks
All times are GMT -5. The time now is 09:39 PM .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know .
Latest Threads
LQ News