ssharish2005,
Here is the code. You can see at line 18, which is commented because malloc() doesn't work here, and i've got to put it at line 35.
Code:
14 struct record * build_record(struct record* rec, int rec_id, string line, string sep){
15 string words[MAX_FIELD];
16 parse_line(words, line, sep);
17
18 //rec = (struct record *)malloc(sizeof( struct record));
19 rec->id = rec_id;
20 rec->name = words[0];
21 rec->birth[0] = 1;
22 rec->birth[1] = 2;
23 rec->birth[2] = 3;
24 rec->remark = words[2];
25 rec->status = '1';
26
27 printf("build record:\t");
28 display_record( rec );
29 return rec;
30 }
31
32 int build_records(struct record* records[], string lines[], string sep){
33 int i;
34 for ( i = 0; lines[i] != NULL; i++ ){
35 records[i] = (struct record *)malloc(sizeof( struct record));
36 build_record( records [i], i, lines[i], sep );
37
38 printf("check record after built, ");
39
40 printf("Record: id: %d, dob: %d, name: %s, remark: %s\n",
41 records[i]->id, records[i]->birth[0], records[i]->name, records[i]->remark);
42
43 }
44
45 return i;
46 }