SEAL Forum Index SEAL
The SEAL Forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

help with linked list

 
Post new topic   Reply to topic    SEAL Forum Index -> Programming Related
View previous topic :: View next topic  
Author Message
w_w_n_uk



Joined: 25 Oct 2001
Posts: 177
Location: England, Hemel Hempstead

PostPosted: Mon Jul 08, 2002 7:16 am    Post subject: help with linked list Reply with quote

Code:

#include "include\vfile.h"
#include "include\debug.h"
#include <stdio.h>
#include <stdarg.h>

/* This is the structure (replace "user" with "node" or whatever you want) */
typedef struct _user {
        char* link;
        char* vlink;
        char* d_type;
   struct _user *next, *prev;
} user;

/* Global pointers to point to first and last element */
user *first_user = NULL, *last_user = NULL;

/* The function to add a new user and return a pointer to this user */
user *add_user()
{
   user *new_user;

   if (last_user != NULL) {
      last_user->next = (user*) malloc (sizeof (user));
      new_user = last_user->next;
      new_user->next = NULL;
      new_user->prev = last_user;
      last_user = new_user;
   } else {
      new_user = (user *) malloc (sizeof (user));
      first_user = new_user; last_user = new_user;
      new_user->next = NULL; new_user->prev = NULL;
   }

   return new_user;
}

/* The function to delete a node and fix the chain (just use with remove_user(pointer_to_node); */
void remove_user(user *current_user)
{
   user *prev_user, *next_user;
   prev_user = current_user->prev;
   next_user = current_user->next;

   if (current_user == first_user) {
      /* first in line so make next one the first in line if exists */
      if (next_user != NULL) {
         first_user = next_user;
         next_user->prev = NULL;
      } else {
         first_user = NULL;
         last_user = NULL;
      }
   } else {
      /* not first in line so connect prev to next */
      if (next_user != NULL) {
         prev_user->next = next_user;
         next_user->prev = prev_user;
      } else {
         prev_user->next = NULL;
         last_user = prev_user;
      }
   }

   free (current_user);
}

char* int2char(char* format, ...)
{                                 
char* make_int2char;

   va_list argptr;

   va_start(argptr, format);

   if (make_int2char)
   {
      vsprintf(make_int2char, format, argptr);
   }

   va_end(argptr);
return make_int2char;
}

int cube_sys_vfs_init() {

int d = 0;
int drv;
char* make_link;
char* make_vlink;
char* make_local;
user *drive;

debug_message("Create virtual drives...", NULL);

while ( d < 27) { // loop to test all dos drives
  if ( _is_remote_drive(d) != -1 ) { // If dos drive exists
    if ( d != 1 ) {
    // debug_message("Drive %c:\\ added as \\local\\%c:\\",'a'+d,'a'+d);
    make_link = int2char("%c:\\ a",'a'+d);
    make_vlink = int2char("%c\\",'a'+d);
    make_local = "local:\\";
    drive = add_user();
    drive->link = make_link;
    drive->vlink = make_vlink;
    drive->d_type = make_local;
    printf("%c",drive->link);
    debug_message("drive %c mapped as %c %c", drive->link, drive->d_type, drive->vlink);
    };
  };
  d++;
};
//add drive code

// remove_user(myuser);

}

i have this code but it dose not add the strings to to list right can any one help??
_________________
leon pegg
W_W_N_UK@YAHOO.CO.UK
When Hell is full, the dead will walk the earth...
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
_xduffy_
Administrator


Joined: 15 Mar 2002
Posts: 894
Location: Sweden

PostPosted: Tue Jul 09, 2002 10:47 am    Post subject: Reply with quote

First of all, this is ugly:
Code:

 user *new_user;

   if (last_user != NULL) {
      last_user->next = (user*) malloc (sizeof (user));
      new_user = last_user->next;

Do:
Code:

 user *new_user = malloc(sizeof (user));
   if (last_user != NULL) {
      last_user->next = new_user;


Anyway, the structure you declare have the name _user and the one you refer to later is named user... Is that the problem?
_________________
http://xduffystuff.sourceforge.net/Desktop/
www.xduffy.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    SEAL Forum Index -> Programming Related All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group