Thread: linked list!!

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    3

    linked list!!

    I have juz started to understand a bit about linked lists...was juz wondering if anyone knew what this code does???

    Thanks for your help

    PHP Code:

    typedef struct linkList
    {
      
    char *line;
      
    struct linkList *next,*prev;
    }
    lineList;

    lineList *head NULL, *tail NULL;

    void addtolink(char *lin,int lin1);
    void printlinklist(lineList *tmp);

    int main(int argcchar *argv[])
    {
      static 
    FILE *fp NULL;
      if (
    argc != 2)  
      {
        
    fprintf(stderr"Usage: %s <filename>\n"argv[0]);
        return 
    0;
      }
      
    char *fname argv[1];

      if (
    fp == NULL)
        {
          if ((
    fp fopen(fname"r")) == NULL)
        {
          
    printf("NEW FILE");
          
    fp fopen(fname"w+");
          
        }
          else
        {
          
    int x 0;
          
    char c;
          
    char lin1[1000];
          
    fp fopen(fname"r");
          while((
    fgetc(fp)) != EOF)
            {
              
              if  ( 
    != '\n')
            {
              
    lin1[x] = c;
              
    1;
              
            }
              else 
            {
              
    lin1[x] = '\0';
              
    char *lin2;
              
    int strlin1 strlen(lin1);
              
    lin2 = (char *)malloc(sizeof(lineList)*(strlin1));
              
    lin2 lin1;
              
              
    addtolink(lin2,strlin1);
              
    0;
            }
            }
        
          
    printlinklist(head->next);
        }
        }
      return 
    0;
    }

    void addtolink(char *lin,int lin1)
    {
      
    char *line2;
      
    lineList *newline;
      
    line2 = (char*)malloc(sizeof(char)*(lin1));
      
    line2 lin;

      if ((
    newline = (lineList*)malloc(sizeof(lineList)))!= NULL)
        {
          
    newline -> line line2;
          if (
    head == NULL)
        {
          
    printf("1");
          
    head newline;
          
    tail newline
        }
          else
        {
          
    printf("2");
          
    tail -> next newline;
          
    newline -> prev tail;
          
    newline ->  next NULL;
          
    tail newline;    
        }
        }
      return;
    }

    void printlinklist(lineList *tmp)
    {
      
    printf("3");
      
    printf("%s",head -> line);
      while (
    tmp != NULL)
        {
          
    printf("%s",tmp -> line);
          
    tmp tmp -> next;
        }

    Last edited by nbp03; 04-23-2006 at 02:54 AM.

  2. #2
    Awesomefaceradcore bivhitscar's Avatar
    Join Date
    Apr 2006
    Location
    Melbourne, Australia
    Posts
    210
    You could always just compile it yourself...

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    3
    i dun have a file to read frm...

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Learn the basics of the language before you try to parse other people's random code bits you find on teh interweb.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Apr 2006
    Posts
    3
    great advice!!....thanks

  6. #6
    Registered User
    Join Date
    Feb 2006
    Location
    Great India
    Posts
    24
    Before knocking at doorstep of LINKED LIST you should be a champ of pointers and i hope if you have learned them by heart you can understand the code very easily.

    So don't be scared while looking at the code you should understand it instead of staring it.



    REALNAPSTER

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ Linked list program need help !!!
    By dcoll025 in forum C++ Programming
    Replies: 1
    Last Post: 04-20-2009, 10:03 AM
  2. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 10:10 AM
  3. Reverse function for linked list
    By Brigs76 in forum C++ Programming
    Replies: 1
    Last Post: 10-25-2006, 10:01 AM
  4. Template Class for Linked List
    By pecymanski in forum C++ Programming
    Replies: 2
    Last Post: 12-04-2001, 09:07 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM