By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,227 Members | 1,376 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,227 IT Pros & Developers. It's quick & easy.

problem with nested structures

P: 3
I having a nested structures which are referenced with pointer variables
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. struct test
  3. {
  4.   int i;
  5.   char *mytest;
  6. };
  7. struct sample
  8. {
  9.   int k;
  10.   struct test *test1;
  11. };
  12. int main()
  13. {
  14.   struct sample *mysample;
  15.   printf("Inside main method \n\n");
  16.   mysample->k=0;
  17.   mysample->test1->i=1;  // It's throws segmentation fault error at this point how to access this variable.
  18.   printf("the value of the k is  %d \n\n",mysample->k);
  19.   //  printf("the value of the k is  %d \n\n",mysample->test->i);
  20.   return 0;
  21. }
  22.  
please help me as soon as possible
Mar 19 '07 #1
Share this Question
Share on Google+
2 Replies


10K+
P: 13,264
Moved to C++ forum.
Mar 19 '07 #2

Expert 100+
P: 1,510
you need to point the pointer sat some objects, e.g.
Expand|Select|Wrap|Line Numbers
  1.  struct sample s;
  2.   struct sample *mysample=&s;
  3.   printf("Inside main method \n\n");
  4.   mysample->k=0;
  5.   struct test t;
  6.   mysample->test1=&t;  
  7.   mysample->test1->i=1;  // It's throws segmentation fault error at this point how to access this variable.
  8.  
Mar 19 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.