Subj : Re: structures problem To : borland.public.cpp.borlandcpp From : Bob Gonder Date : Sat Jul 24 2004 09:16 am Viktor Popov wrote: >struct SSEList{ >char type[5]; ----------------------------->I don't use this. If I comment >this row everything goes wrong.... the first element of the structure is not Fix your other problems and this one should go away. >}*sse; > if((sse=(struct SSEList *)malloc(100*sizeof(struct SSEList)))==NULL) > if((fp = fopen(argv[1], "r")) == NULL){ Specify the mode. Use either "rt" or "rb" > struct SSEList *s=(struct SSEList *)malloc(100*sizeof(struct SSEList)); > s = BuildSSE(fp,sse); This is wrong. 3 different ways to make it right. 1) Pass s to BuildSSE so it can fill it in (no return value). void BuildSSE(FILE *fp,struct SSEList *sse, struct SSEList *s) 2) Don't allocate s. You are returning the address of sse anyway, so that s points to sse. 3) (the best) Just skip 's' totally and use sse after returning. void BuildSSE(FILE *fp,struct SSEList *sse) Use the filled-in sse. >struct SSEList *BuildSSE(FILE *fp,struct SSEList *sse) >{ > >char *str,*temp,*ime; >int h=0,s=0; > > >br=0; >do{ > fgets(str,200,fp); You read into str, but you haven't allocated memory for str. char str[200]; Likewise temp and ime .