I have decalred a struct using:
And declared an array of structs usingCode:struct MEM { char MEMarray[7]; };
How do I then start storing stuff into my MEMarray?Code:struct MEM arrayOfStructs[10];
This is a discussion on Problem with array of structs within the C Programming forums, part of the General Programming Boards category; I have decalred a struct using: Code: struct MEM { char MEMarray[7]; }; And declared an array of structs using ...
I have decalred a struct using:
And declared an array of structs usingCode:struct MEM { char MEMarray[7]; };
How do I then start storing stuff into my MEMarray?Code:struct MEM arrayOfStructs[10];
Code:strcpy(arrayOfStructs[0].MEMarray,"Hello!");
Sent from my iPadŽ
Ah very clever, thanks.
here is one more example for you
ssharish2005Code:#include<stdio.h> struct SomeTestStruct { int SomeDataAsInt; char SomeDataAsString[20]; float SomeDataAsFloat; }; int main() { struct SomeTestStruct SomeTestStructArray[5] = {{10,"Test 1",20.5}, {20,"Test 2",30.5}, {30,"Test 3",40.5}, {40,"Test 4",50.5}, {50,"Test 5",60.5}}; int i; printf("This is Struct Initialization\n"); printf("=============================\n\n"); for(i=0;i<5;i++) printf("%d %s %f\n",SomeTestStructArray[i].SomeDataAsInt,SomeTestStructArray[i].SomeDataAsString, SomeTestStructArray[i].SomeDataAsFloat); getchar(); return 0; } /*my output This is Struct Initialization ============================= 10 Test 1 20.500000 20 Test 2 30.500000 30 Test 3 40.500000 40 Test 4 50.500000 50 Test 5 60.500000 */