GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 27-Oct-2004, 22:51
Newworld Newworld is offline
New Member
 
Join Date: Sep 2004
Posts: 7
Newworld is on a distinguished road

compiler errors


having a lot of trouble with my code... so I'll start with my insert function.

in my insert function:
project3.c:22: `node' undeclared (first use in this function)
project3.c:22: (Each undeclared identifier is reported only once
project3.c:22: for each function it appears in.)
project3.c:22: parse error before ' ) ' token
project3.c:32: warning: assignment makes pointer from integer without a cast
project3.c:37: warning: assignment makes pointer from integer without a cast

here is my code:

CPP / C++ / C Code:
#include <stdio.h>
#include "rndm.h"

struct node
{
    int data;
    unsigned long link;
};

struct node *head, *tail;

/*Function to insert node into list*/
void insert(int num)
{
	struct node *tmp, *next, *prv, *cur;
	tmp= (node *) malloc (sizeof(struct node));
    prv=0;
    cur=head;
    next=head;
    if(head==NULL)
	{
	    head=tmp;
	    tmp->link=0;
	    tail->link=(unsigned long)tmp;
    }else{
        next= cur->link^(unsigned long)prv;
        while(tmp->data > cur->data && cur->link^next->link !=0)
        {
                prv= cur;
                cur= next;
                next= cur->link^(unsigned long)prv;
		}
		if(cur->link^next->link ==0)
		{
		        tail=tmp;
        }else{
        }
        prv->link ^= (unsigned long)cur^(unsigned long)tmp;
		cur->link ^=(unsigned long)prv^(unsigned long)tmp;
		tmp->link = (unsigned long)prv^(unsigned long)cur;
	}
    
}

/*Function To print out data contents of each node*/
void list()
{
	struct node *tmp, *cur, *next, *prv;
    printf("%d",&head->data);
	prv=0;
	cur=head;
	next=(unsigned long)prv^(unsigned long)cur;
	while(next->link^cur->link!=0)
	{
		printf("%d ",&cur->data);
		prv=cur;
		cur=next;
		next=cur->link^(unsigned long)prv;
	}



}

int main{
    
	init_seed(123456);
	set_range(1,9999);
	int x=0;
	int i;
    head=NULL;
	tail=NULL;
	for(i=0;i<100;i++)
	{
	    x=rndm();
	    insert(x);
    }
	list();




}
Last edited by LuciWiz : 28-Oct-2004 at 01:51. Reason: Please insert your C code between [c] & [/c] tags (not generic [code])
  #2  
Old 28-Oct-2004, 08:07
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Hello Newworld. I can help you a bit with your comile errors, but not your logic. I am not sure why the heavy usage of the bitwise xor operator in this. If you get a chance, I would love to hear what this is doing....

The error at line 22, you need to include struct:
CPP / C++ / C Code:
tmp= (struct node *) malloc (sizeof(struct node));


The warnings need to be typecast. You are assigning an unsigned long but it is looking for a struct node *. They are the same thing, but it is best to not have any warnings. It also forces you to explicitly think about typecasting. It is not something to do lightly and should only be done when you are sure of what you are doing:

CPP / C++ / C Code:
next= (struct node *) (cur->link^(unsigned long)prv);


There are other errors as well that you should unearth now... Since I am not sure exactly what you want to do, I will only point out the ones that you asked about.

Good luck.
 
 

Recent GIDBlogToyota - 2008 November Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
help to debug complier errors nkhambal C Programming Language 3 04-Oct-2004 09:26
32 bit compiler needed meet_raman C++ Forum 2 24-Jun-2004 04:42
Can somebody look at this and point out any errors to me soulfly C Programming Language 7 31-Mar-2004 10:45
a noobish compiler question Charunks C++ Forum 5 03-Sep-2003 03:18
i need a free Mac compiler yerdos C++ Forum 1 28-Jul-2003 03:12

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 06:19.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.