[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
 

SV: [PROGRAMMERING] [C] Array, pointer og struct



>
>Jeg har en struct der er defineret som:
>
>struct block {
>     int number;
>     struct block *next;
>};

burde være lovlig :-)

>
>Som man nok kan se, er det menningen at den skal lave en linked liste 
>med sig selv.
>
>Samtidigt bliver alle blocks gemt i en array
>
>struct block blocks[25];
>
Du definere et array af 'blocks', og samtidigt holder du adressen på den næste block i din struct? Det virker sært. Når du har defineret et array har du allerede alle adresserne og kan refere til de andre per nummer i arrayet i stedet for at gemme deres adresser - det burde være mere overskueligt.

>Endvidere har jeg også en funktion som skal bruges til at manipulere 
>disse structs med.
>
>void moveOnto(int *from, int *to) {
>     if (blocks[*from].next != NULL) {
>         returnBlock(blocks[*from].next);
>     }
>
>}
>

hvorfor er det pointere til integers?

>
>
>void returnBlock(struct block *block) {
>     if (*block.next != NULL) {
>
>     }
>}
>
>
>Når jeg kompilerer min kode, så får jeg fejlen:
>
>
>>> 000101.c:  In function `returnBlock':
>>> 000101.c:110: error: request for member `next' in something not a >structure or union
>>  
>>
>
>Jeg vil umiddelbart antage at fejlen ligger i:
>returnBlock(blocks[*from].next);
>
enig.
Med den returnblock du har defineret skal du sende adressen på din block af sted. 
	returnBlock( &blocks[*from].next);
burde virke.

Men overvej at lave din struct om. Det er mere gennemsigtigt at referere til block i istedet for at sende adressen videre.

Mvh morten


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 22:44 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] *