This Program Is An Simple But An Complex Shopping Program. When I Run The Program Everything Is Fine. But When I enter The Product Name And I Pass The Function add_to_cart() It Says Abnormal Program Termination And Null Pointer Assignment And Creates An File "1PD.txt" Which I Don't Want To Create.Please Help Me Out . All Other Functions Are Fine.
I Tried A Lot Possible Out Comes But It Ain't Working. Right Now I Am Way Too Confused On What To Do.
void add_to_cart(int se_id,int c_id,char p_name[])
{
char id_seller[100],id_customer[100],id_seller1[100],id_customer1[100];
itoa(se_id,id_seller,10);
itoa(se_id,id_seller1,10);
itoa(c_id,id_customer,10);
itoa(c_id,id_customer1,10);
strcat(id_seller,"pd.txt");
strcat(id_seller1,"pr.txt");
strcat(id_customer,"itm.txt");
strcat(id_customer1,"prz.txt");
char prod_l[]="C:\\TURBOC3\\BIN\\BANK\\SHOP\\SELLER\\",priz_l[]="C:\\TURBOC3\\BIN\\BANK\\SHOP\\SELLER\\";
strcat(prod_l,id_seller);
strcat(priz_l,id_seller1);
char cart_itm[]="C:\\TURBOC3\\BIN\\BANK\\SHOP\\CART\\",cart_priz[]="C:\\TURBOC3\\BIN\\BANK\\SHOP\\CART\\";
strcat(cart_itm,id_customer);
strcat(cart_priz,id_customer1);
ifstream file,file1;
ofstream file2,file3;
file.open(prod_l,ios::in);
file1.open(priz_l,ios::in);
file2.open(cart_itm,ios::app);
file3.open(cart_priz,ios::app);
int i=0,j=0,prizee[100],flag_pos;
char name_product[100][100];
while(!file.eof())
{
file>>name_product[i];
if(strcmpi(p_name,name_product[i])==0)
flag_pos=i;
i++;
}
while(!file1.eof())
{
file1>>prizee[j];
if(flag_pos==j)
file3<<prizee[j]<<endl;
j++;
}
file2<<name_product[flag_pos]<<endl;
file3<<prizee[flag_pos]<<endl;
file1.close();
file3.close();
file.close();
file2.close();
textcolor(GREEN+BLINK);
cprintf("Product Has Been Added To Your Cart Successfully");
cout<<endl;
}
I Expect The Output To Be "Product Has Been Added To Your Cart Successfully".
Aucun commentaire:
Enregistrer un commentaire