I wrote a program about structs and pointers...but i think i have one mistake! Please take a look at the code:
I suppose my serious problem is only at the red mark and more specific when initializing the pointer! I hope so...
Thank you in advance...Code:#include <stdio.h> #include <stdlib.h> #include <time.h> struct Packet{ int id; char content[5]; }; int intit_Max(struct Packet A[], int size){ int i, j, maxS; struct Packet max5; for(i=0; i<size; i++){ A[i].id=rand(); for(j=0; j<4; j++){ A[i].content[j]=(char)(rand()%26+'a'); A[i].content[5]='\0'; printf("%12d%s\n", A[i].id, A[i].content); } maxS=A[0].id; for(i=0; i<size; i++){ if( A[i].id > maxS ){ maxS=A[i].id; return maxS; } } } } int main(void){ struct Packet A[10]; struct Packet *myS; myS = init_Max(A, 10); printf("\nMax: %d%f\n", myS.id, myS.content); }



LinkBack URL
About LinkBacks



