CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2009
    Posts
    4

    Unhappy compiling problem

    this program gives an error when i try to compile... i could not fix it. can anyone help me???

    Code:
    #include <stdio.h>
    #include <conio.h>
    #include <string.h>
    
    typedef struct node {
            int num;
            struct node *test;
    } new1;
    new1 *sList;
    void list_show (new1 *);
    new1 list_sort(new1 *, new1 *); 
    
    int main () 
    {
        new1 nod4 = {18,NULL};
        new1 nod3 = {15,&nod4};
        new1 nod2 = {14,&nod3};
        new1 nod1 = {10,&nod2};
        sList=&nod1;
        
        new1 tempnod = {12,NULL};
        printf ("initial\n");
        list_show(sList);
        sList=list_sort(sList,&tempnod);
        printf("Sorted List \n", tempnod.num);
        list_show(sList);
        
        getch();
        return 0;
    }
    void list_show (new1 *list) 
    {
          new1 *ptr=list, *j=NULL;
          while (ptr!=NULL)
          {
                printf("%d", ptr->num);
                ptr = ptr->test;
                }
    new1 list_sort(new1 *list, new1 *tempnod) 
    {
          new1 *ptr=list, *j=NULL;
          while (ptr!=NULL)
          {
         
                if ((ptr->num)<(tempnod->num))
                {
                   j=ptr;
                   }
                ptr = prt->test;
                }
                if (j!=NULL)
                {
                            tempnod->test=j->test;
                            j->test=tempnod;
                            } else 
                            {
                                   tempnod->test=list;
                                   list=tempnod;
                                   }
                            return list;
                            }

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: compiling problem

    Is it asking too much to tell us the error and the line number? Really?

  3. #3
    Join Date
    Jan 2004
    Location
    Düsseldorf, Germany
    Posts
    2,401

    Re: compiling problem

    Properly indenting your code will lead you to the problem.
    More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity. --W.A.Wulf

    Premature optimization is the root of all evil --Donald E. Knuth


    Please read Information on posting before posting, especially the info on using [code] tags.

  4. #4
    Join Date
    Jan 2003
    Posts
    615

    Re: compiling problem

    First of all, definiting a type called "new1" is just plain annoying.

    In the below code 'sList' is a pointer but the method list_sort does not return a pointer.
    Code:
    new1 *sList;
    
    new1 list_sort(new1 *, new1 *); 
    
    sList=list_sort(sList,&tempnod);
    Another thing,
    Code:
    void list_show (new1 *list) 
    {
          new1 *ptr=list, *j=NULL;
          while (ptr!=NULL)
          {
                printf("&#37;d", ptr->num);
                ptr = ptr->test;
           }
    }
    
    new1 list_sort(new1 *list, new1 *tempnod) 
    {
          new1 *ptr=list, *j=NULL;
         ...
    }
    A third thing,
    Code:
    printf("Sorted List \n", tempnod.num);
    You do not use the variable tempnod.num in the printf, remove it or use it.
    Last edited by laasunde; November 23rd, 2009 at 09:09 AM.
    Before post, make an effort yourself, try googling or search here.

    When posting, give a proper description of your problem, include code* and error messages.

    *All code should include code tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured