I have this error 'realloc' : cannot convert parameter 1 from 'stock' to 'void *' but i cant seem to find why ive read about realloc() but i know i need to use malloc() first or calloc() i just cant seem to get the jist of the idea thanks
Code:
printf("Lists stock\n");{
FILE *fp; //file pointer
fp=fopen("stock.txt","r");
stock mylist[50];
while(1) /* infinite loop */
fp=fopen("stock.txt","r");
malloc( 1000 * sizeof( struct stock) == NULL );
Nfields = fscanf(fp, "'%d %s %d\n", &mylist[i].product_id, &mylist[i].product_name, &mylist[i].stock_level); /* fscanf returns the number of fields it successfully read */
if(Nfields != 3) /* if we didn't read three fields, we're at the end of the data */
break;
mylist = realloc(mylist[i], (i +1) * sizeof(struct stock)); /* or whatever you called the structure */
if(!mylist)
mylist[i].product_id;
strcpy(mylist[i].product_name,pointer);
mylist[i].stock_level;
{
printf("Product Name:%s\n",mylist[i].product_name);
printf("Product_ID:%d\n ",mylist[i].product_id);
printf("Stock Level:%d\n\n",mylist[i].stock_level);
}