[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Dumt problem med länkad lista.



Hejsan !

Jag har försökt att skapa mig en simpel länkad lista.
Tyvärr, så får jag itne ut önskat resultat. Sannolikt, så är det en tankemiss
från min sida för så svårt att skapa en sådan kan det väl inte vara.

hade varit kul om någon hade kunant rätta mina fel för jag råkar vara i lite
smått desperat behov utav den.

Bifogad källkod:

#include <stdio.h>
#include <malloc.h>


struct Test
{
	int varde;

	struct Test *nasta;
};


void init(struct Test *tp);


void main()
{
	struct Test *ny,*org;

/*
	ny=(struct Test*)malloc(sizeof(struct Test));

	init(ny);

	ny->varde=10;
	org=ny;

	ny=(struct Test*)malloc(sizeof(struct Test));
	init(ny);
	ny->varde=20;
	ny->nasta=org;
*/

	int i;

	while(1)
	{
		printf("Ange ett heltal > ");
		scanf("%d",&i);
		if(i==-1)
			break;
		
		ny=(struct Test*)malloc(sizeof(struct Test));
		init(ny);
		ny->varde=i;
		org=ny;
		ny->nasta=org;
	}
	
	while(1)
	{
		printf("ny-varde = %d\n",ny->varde);
		//ny=org;
		if(ny->nasta==NULL)
			break;
		org=ny->nasta;
		free(ny);
		ny=org;
	}



}




void init(struct Test *tp)
{
	tp->varde=0;
	tp->nasta=NULL;
}



 --

/Jocke

ICQ uin: 3939304

----------------------------------------------------------------

***     Linux..... The choice of a thinking generation     *****

----------------------------------------------------------------



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:07 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *