Hello people, I'm getting some problems with the following function:
Code:
extern struct product products[1000];
int loadDB (struct product products[], char *filepath)
{
FILE *fpData; /* pointer to the file that we'll get the data */
int i = 0; /* the index for filling the structure array */
/* try to open the file and check for errors */
if ((fpData = fopen(filepath,"r")) == NULL)
return (EXIT_FAILURE);
#ifdef DEB
printf("hhehe");
#endif
while (fscanf(fpData,"%d%d%d%f%s%s%s%s",&products[i].pr_code,&products[i].pr_inv,&products[i].pr_min_inv, &products[i].pr_price, products[i].pr_name,products[i].pr_supplier,products[i].pr_sup_tel,products[i].pr_sup_fax) == 8)
i++;
/* check if we at least got a single value, if not, return fail (0) */
if (products[0].pr_code == 0)
return 0;
return 1;
}
The first extern is to get a global array of structures declared in main.c, this file is market.c.
My program freezes when I call this function, I can see the HEEE msg, but afters this, all goe's down.