So, Im kinda new to C. I am making a simple I/O Program but facing a problem.
So I have this Struct:
Code:
struct stock{ //Struct for storing stock data
char item_name[100];
float item_rate;
int item_quantity;
}stock_[MAX_SIZE];
For Example, I Input the following Data:
1.
item_name: shoes
item_rate: 100
item_quantity: 200
2.
item_name: shoes
item_rate: 100
item_quantity: 200
Now I want to delete the second entry of data from struct ie shoes, its rate and its quantity. How do I do that? For now I am using the strcmp to compare input string with that of data saved and replace it with Null string using strcpy. But that doesnt seem feasible solution to me.
Here is my Code:
Code:
char item_delete[50];
char new_name_delete[50]={'\0'};
int compare_delete;
retry_search_case_3:
printf("\n\t\tEnter item name to Delete(case sensitive): ");
scanf("%s",item_delete);
for(i=0;i<index_stock;i++)
{
compare_delete=strcmp(stock_[i].item_name,item_delete);
if(compare_delete==0)
{
printf("\n\t\t%s item found. Its Entry Number in Stock is %d\n\t\tDeleted this Item from Stock\n\t\tPrinting Updated Stock...\n\t\t",item_delete, i+1);
strcpy(stock_[i].item_name,new_name_delete);
stock_[i].item_rate=0;
stock_[i].item_quantity=0;
system("pause");
break;
}
else
{
printf("\n%s item not found! Please try again: ",item_delete);
continue;
}
I know how to delete a simple element from a 1D Array, I tried to implement that here but didnt work. As that algorithm compares two input integers instead of strings and then re-sorts the array