Trouble spot!

Michael N Johnston id8rld06 at serss0.fiu.edu
Mon Apr 15 01:45:57 AEST 1991


] void find()
] {
]        [...]
]    if((fptr=fopen("maillist.txt","r"))==NULL) {
]        [...]
]    fscanf(fptr,"%s %s %s %s %d", addr_info[t].name, addr_info[t].street, addr_info[t].city, addr_info[t].state, addr_info[t].zip);
]        [...]
] }

    Notice that here in find(), you are opening the file for read and doing
FORMATTED input.

] void save()
] {
]         [...]
] if((fp=fopen("maillist.txt","wb"))==NULL) {
]         [...]
] if(fwrite(&addr_info[i],sizeof(struct addr),1,fp)!=1)
]         [...]
] }

    But here in save(), you are opening the file for write in BINARY mode
and doing UNFORMATTED output.
    You need to change the open and read in find() to unformated, binary
input as you have below in load().

] void load()
] {
]         [...]
] if((fp=fopen("maillist.txt","rb"))==NULL) {
]         [...]
] if(fread(&addr_info[i],sizeof(struct addr),1,fp)!=1) {
]         [...]
] }

Mike
--
====================================================================
Michael Johnston
id8rld06 at serss0.fiu.edu or
26793271x at servax.fiu.edu



More information about the Comp.lang.c mailing list