Thread: issue with linked list !!IMPORTANT

  1. #16
    Registered User
    Join Date
    Apr 2013
    Location
    Gurgaon, Haryana, India
    Posts
    41
    Guys this is the error that the windows crash dialogue box is showing
    Problem signature: Problem Event Name: APPCRASH
    Application Name: ntest11.exe
    Application Version: 0.0.0.0
    Application Timestamp: 51c08bb6
    Fault Module Name: ntest11.exe
    Fault Module Version: 0.0.0.0
    Fault Module Timestamp: 51c08bb6
    Exception Code: c0000005
    Exception Offset: 00001372
    OS Version: 6.1.7600.2.0.0.256.1
    Locale ID: 16393
    Additional Information 1: 0a9e
    Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
    Additional Information 3: 0a9e
    Additional Information 4: 0a9e372d3b4ad19135b953a78882e789


    Read our privacy statement online:
    Windows 7 Privacy Statement - Microsoft Windows


    If the online privacy statement is not available, please read our privacy statement offline:
    C:\Windows\system32\en-US\erofflps.txt


  2. #17
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What is your current code? Use a debugger to find out at which point the crash occurs. Your mistake lies in code that is executed before that point.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #18
    Registered User
    Join Date
    Apr 2013
    Location
    Gurgaon, Haryana, India
    Posts
    41
    okay i'll try

  4. #19
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    in code::blocks are u using gnu/gcc compiler?
    Yes, version 4.8.0 to be exact.
    how did u increased the errors and warnings as i could only increase the errors.
    I read the manual on my IDE and compiler and set the required settings.

    issue with linked list !!IMPORTANT-projectsettings-jpg

    issue with linked list !!IMPORTANT-projectsettings2-jpg

    rest i work on linux at school and there return type mentioning is not necessory .thats y i never came across mentioning a return type .
    That's not true, every C/C++ program requires a main() that returns an int, unless you're dealing with embedded. Even your broken program returns an int. In C90 the compiler assumes you mean int when you don't provide the type. But the current C standard requires you provide the return type.

    plus what does this mean :
    main.c||In function ‘create_link’:|
    main.c|69|warning: control reaches end of non-void function [-Wreturn-type]|
    What do you think it means?

    How did you define this function?

    What type of value did you promise the compiler you would be returning?

    Did you actually return the type of value you promised the compiler you would return?


    These are very basic error/warning messages that you should have run into by now. This project is not a basic problem so you should already know how to properly write and use functions. And you should be getting used to the messages your compiler should be generating.

    Jim
    Last edited by jimblumberg; 06-18-2013 at 10:44 AM.

  5. #20
    Registered User
    Join Date
    Apr 2013
    Location
    Gurgaon, Haryana, India
    Posts
    41
    @jim i noted all your points and increased my errors the last error i asked i rectified it but there is one erro m not able to solve
    D:\softwareinstall\Codeblocks workspace\testprogs\ntest11.c|21|warning: 'trys' is used uninitialized in this function [-Wuninitialized]|
    i did initialised trys as *trys abuv in my code.

  6. #21
    Registered User
    Join Date
    Apr 2013
    Location
    Gurgaon, Haryana, India
    Posts
    41
    errors=*warnings

  7. #22
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    i did initialised trys as *trys abuv in my code.
    Obviously not or your compiler wouldn't be telling you about the issue. But for a better answer you'll need to post your current code.

    Jim

  8. #23
    Registered User
    Join Date
    Apr 2013
    Location
    Gurgaon, Haryana, India
    Posts
    41
    @jim
    Code:
    #include<stdio.h>#include<strings.h>
    #include<stdlib.h>
    #include<malloc.h>
    
    
    struct node
    {
        int data;
        struct node *next;
    };
    
    
    typedef struct node link;
    
    
    link create_link(link *r);
    
    
    int main()
    {
        link *trys,*k;
        int i,j,num;
    
    
        k=trys;
    
    
        printf("Enter the Number  data\n");
        scanf("%d",&num);
        trys->data=num;
        trys->next=NULL;
        p: printf("\nDo you want to add more numbers?(Y=1/N=0)");
        scanf("%d",&i);
        if(i==1)
        {
            for(j=0;trys->next==NULL;j++)
                    trys=trys->next;
            create_link(trys);
            {
                trys=k;
                for(j=0;trys->next==NULL;j++)
                    trys=trys->next;
                printf("\nEnter the next Number data\n");
                scanf("%d",&num);
                trys->data=num;
            }
            trys=k;
            goto p;
        }
        else
        {
            printf("\nNumber dat entered by you is:\n");
            for(j=0;trys->next==NULL;j++)
            {
                printf("%d\n",trys->data);
            }
        }
        return 0;
    }
    
    
    link create_link(link *r)
    {
        link *addon;
    
    
        addon=malloc(sizeof(link));
        r->next=addon;
        addon->next=NULL;
        return *r;
    }

  9. #24
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Look at the following snippet:
    Code:
        link *trys,*k;
        int i,j,num;
    
    
        k=trys;
    Where have you initialized trys?

    Jim

  10. #25
    Registered User
    Join Date
    Apr 2013
    Location
    Gurgaon, Haryana, India
    Posts
    41
    okay okay please correct me is *trys not an initialisation for trys as it is for k in the link datatype and how will i initialise an address as trys is actually an address.

  11. #26
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    okay okay please correct me is *trys not an initialisation for trys as it is for k in the link datatype and how will i initialise an address as trys is actually an address.
    The warning is about *trys. You have not initialized this variable before you try to initialize k. At this point you don't know where *trys is pointing.

    You need to either allocate memory for this uninitialized pointer (*trys) or assign the pointer to a valid memory location.

    Jim

  12. #27
    Registered User
    Join Date
    Apr 2013
    Location
    Gurgaon, Haryana, India
    Posts
    41
    @jim can you explain with an example

  13. #28
    Registered User
    Join Date
    Apr 2013
    Location
    Gurgaon, Haryana, India
    Posts
    41
    okay got your point jim corrected it by a malloc.

  14. #29
    Registered User
    Join Date
    Jun 2013
    Posts
    6
    i'm also beginner to c/ds & this forum, can somebody please comment on this, if i'm wrong, Thanks in advance.


    Quote Originally Posted by Amitesh93 View Post
    @jim
    Code:
    #include<stdio.h>#include<strings.h>
    #include<stdlib.h>
    #include<malloc.h>
    
    
    struct node
    {
        int data;
        struct node *next;
    };
    
    
    typedef struct node link;
    
    
    link create_link(link *r);
    
    
    int main()
    {
        link *trys,*k;
        int i,j,num;
    
    
        k=trys;
    
        trys = (link *) malloc (sizeof(link)); 
        printf("Enter the Number  data\n");
        scanf("%d",&num);
        trys->data=num;   //previously crash was happened here, now memory is allocated so here crash wont happen.
        trys->next=NULL;
        p: printf("\nDo you want to add more numbers?(Y=1/N=0)");
        scanf("%d",&i);
        if(i==1)
        {
    /*        for(j=0;trys->next==NULL;j++)   //this also wrong, you have to try until u reach null  
                    trys=trys->next;
       */
             for(j=0;trys->next!=NULL;j++) 
                   trys=trys->next;
            k = create_link(&trys); // k points to the allocated memory
            {
    //         trys=k;     // here you are assigning k to trys, as of your code, memory is not allocated for trys, again while accessing trys may crash.
    //         for(j=0;trys->next==NULL;j++)   
    //             trys=trys->next;
                printf("\nEnter the next Number data\n");
                scanf("%d",&num);
                trys->data=num;
            }
           // trys=k;
            goto p;
        }
        else
        {
            printf("\nNumber dat entered by you is:\n");
            //for(j=0;trys->next==NULL;j++)
            for(j=0;trys->next!=NULL;j++)
            {
                printf("%d\n",trys->data);
            }
        }
        return 0;
    }
    
    
    link create_link(link **r)
    {
        link *addon;
    
    
        addon=malloc(sizeof(link));
        *r->next=addon;
        addon->next=NULL;
        return addon;
    }

  15. #30
    Registered User
    Join Date
    Apr 2013
    Location
    Gurgaon, Haryana, India
    Posts
    41
    @pappu i actually corected the == to != operator it was just for testng dat i did but @ line 57 do u want me to use ==

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. linked list issue
    By Hayat Qyrt in forum C Programming
    Replies: 16
    Last Post: 10-27-2012, 05:40 AM
  2. linked list issue
    By roaan in forum C Programming
    Replies: 6
    Last Post: 09-01-2009, 01:21 AM
  3. Doubly Linked List Deletion Issue
    By josephjah in forum C++ Programming
    Replies: 22
    Last Post: 07-22-2007, 03:00 PM
  4. Linked list copy constructor issue
    By Craptastic! in forum C++ Programming
    Replies: 1
    Last Post: 08-03-2003, 08:30 PM

Tags for this Thread