Pointer to a Pointer to a struct

From: Rodrick Brown (rbrown[_at_)
Date: 10/15/04

  • Next message: Joona I Palaste: "Re: Pointer to a Pointer to a struct"
    Date: Fri, 15 Oct 2004 07:07:40 GMT
    
    

    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>

    int
    main(void)
    {
      typedef struct
      {
        char **test;
      }Testing;

      Testing **p;
      p = malloc(sizeof(Testing));
      p[0]->test[0] = malloc(sizeof(Testing));
      strncpy(p[0]->test[0],"Hello World",20);
      printf("%s\n",p[0]->test[0]);

      return EXIT_SUCCESS;
    }

    Why does the following crash ?
    Not sure what i'm missing please advise thanks.

    -- 
    Unix Systems Engineer 
    The City of New York 
    Dept. of Information Technology
    http://www.nyc.gov/doitt
    rbrown[(@)]doitt.nyc.gov 
    http://www.rodrickbrown.com
    

  • Next message: Joona I Palaste: "Re: Pointer to a Pointer to a struct"

    Relevant Pages

    • Re: Pointer to a Pointer to a struct
      ... > Not sure what i'm missing please advise thanks. ... you have not allocated sufficent amount of memory to the test. ... As a result,the program will crash as soon as return statement will ...
      (comp.lang.c)
    • Re: The W problem
      ... "Rob Giordano (aka: Crash Gordon®)" ... system font to Arial I now see the missing part of the W on system ...
      (microsoft.public.frontpage.client)
    • Re: Which crash next?
      ... Unless he feels he is missing a sound, ... suggested a bigger crash. ... > Opinions of other drummers should be taken lightly because what sounds ...
      (rec.music.makers.percussion)
    • Re: MFC: adding a control into a dialog window
      ... I am using a button ID_ENABLE to trigger the adding of label into IDD_HELLO_DIALOG. ... The program would crash when I hit the button. ... The big thing you are missing is telling us what the dialog assertion says. ... GetDlgItemwill get the CWnd* of a child control of the dialog, ...
      (microsoft.public.vc.mfc)
    • Re: MFC: adding a control into a dialog window
      ... The program would crash when I hit the button. ... The big thing you are missing is telling us what the dialog assertion says. ... But I would imagine that the problem is that your parentwnd is NULL. ... GetDlgItemwill get the CWnd* of a child control of the dialog, and there is not one with the ID IDD_HELLO_DIALOG. ...
      (microsoft.public.vc.mfc)