Web Analytics Made Easy -
StatCounter Help with C arrays and pointers - CodingForum

Announcement

Collapse
No announcement yet.

Help with C arrays and pointers

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help with C arrays and pointers

    I want to access a member of a struct which is a pointer to the same type of struct in the same array, then access its member, an int, and increase its value by one.
    arrayOfStructs[int].pointerToAnotherarrayOfStructs->int++;
    Does not produce any errors or warnings, but crashes when reached by the program.
    Help?

  • #2
    Untested and I haven't touched C for several years. Try it anyway

    PHP Code:
    /* assume */

    struct mystruct
    {
     
    char whatever[10];
     
    int someint;
    }

    struct mystruct *ptr[100];  /* assume 100 entries */

    int n 1;

    ptr[n]->someint++;  /* how to increment the int field in mystruct. */ 

    Comment


    • #3
      It must be most probably because of memory access violations. It is not easy for me to deduce the problem by just looking at that line of code, because it looks fine to me. Could you please post the function that includes that fragment of code? There is no syntax error, it might be because you may not have initialized the pointer variable.

      Comment

      Working...
      X