This might be a dumb question but I'm just learning C.
I have declared:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct STRUCTURE{
char name[30];
}STRUCT;
int main(void){
STRUCT struct1[30] // declaring 30 structs.
STRUCT *pointer;
pointer = &struct1;
return 0;
}
Now, if I wanted to reference to specific struct (of the 30 structs) I could do it like:
&struct[0] // first struct's memory location
&struct[1] // second struct's memory location
...
&struct[i] // where i = 0, 1, 2, 3, 4, 5 ... 29
But how would I do it using the pointer?
I thought by incrementing the pointer I could traverse the structs:
pointer++
But I can't seem to be getting from struct1[i] to struct1[i+1] with pointer++
pointer = &struct1;is invalid C. Didn't you get a message from the compiler? Which compiler are you using and what warning levels are used? Also, no semicolon here:STRUCT struct1[30]&struct1would give you a pointer to a pointer, which is not what you want.gccI will at least recommend:gcc -Wall -Wextra -Werror