segmentation error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sridhard2406
    New Member
    • Dec 2007
    • 52

    segmentation error

    Hi All,

    Below mentioned code gives the segmentation fault when I executed,
    please help me, what is the wrong with my code.

    Code:
    #include <stdlib.h>
    #include <stdio.h>
    
    struct student
    {
            char *name;
            char *place;
    };
    
    main()
    {
            struct student *tmp;
            (tmp->name) = (char *)malloc(90);
            (tmp->place) = (char *)malloc(90);
            printf("%d\n",sizeof(tmp->name));
    
    }
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    tmp, name and place are all pointers. You allocate memory for name and place to point to but you never allocate any memory for tmp to point to.

    Please post code in [code]...[/code] tags.

    Comment

    • sridhard2406
      New Member
      • Dec 2007
      • 52

      #3
      Thanks for your reply

      Comment

      Working...