Dear guys,
I'm facing some problem about the Name is not displaying as I expected..
Code:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
int selection = 0; //Always return 0 after a function is executed
struct productInfo
{
int categoryID;
char categoryName[50];
int productID;
char productName[50];
float productPrice;
int productUnit;
struct productInfo *nextPtr;
};
struct productInfo get;
struct productInfo *tempStorage;
struct productInfo *previousPtr = NULL;
void mainMenu (void);
void addItem (void);
void deleteItem (void);
void updateItem (void);
void sortItem (void);
void display (void);
/*In this problem, you will need to create an inventory system
that enable user to add, delete,
update product category (example: id, name)
product info (example: id, name, price, inventory level etc).*/
int main()
{
do
{
mainMenu(); //Pick an option
} while (selection == 0);
}
void mainMenu (void)
{
printf("~*~*~*~Welcome to the main menu~*~*~*~\n"
" 1 to add a category or item\n"
" 2 to update a category or item\n"
" 3 to delete an category or item\n"
" 4 to end\n"
"?");
scanf("%d", &selection);
switch(selection)
{
case 1:
addItem();
//sortItem();
//system("CLS");
display();
break;
case 2:
deleteItem();
break;
case 3:
updateItem();
break;
default:
printf("Re-enter");
selection = 0;
}
}
void addItem (void)
{
int tempCategoryID = 0;
int tempProductID = 0;
char tempCategoryName[50];
char tempProductName[50];
float tempProductPrice = 0.00;
int tempProductUnit = 0;
int decision = 0;
fflush(stdin); //make sure all the buffered output is flushed
printf("Please key in the Category ID :\n");
scanf("%d", &tempCategoryID);
fflush(stdin);
printf("Please key in the Category Name :\n");
scanf("%[^\n]", tempCategoryName);
fflush(stdin);
printf("Key in 1 if you have a product to store.\nKey in others number to skip.\n");
scanf("%d", &decision);
if (decision == 1) {
fflush(stdin);
printf("Please key in the Product ID :\n");
scanf("&d", &tempProductID);
fflush(stdin);
printf("Please key in the Product Name :\n");
scanf("%[^\n]", tempProductName);
fflush(stdin);
printf("Please key in the Product Price :\nRM");
scanf("%f", &tempProductPrice);
fflush(stdin);
printf("Please key in the Product Unit :\n");
scanf("%d", &tempProductUnit);
} else {
tempProductID = tempCategoryID*100;
tempProductName[0] = '\0';
tempProductPrice = 0.00;
tempProductUnit = 0;
}
tempStorage = malloc(sizeof(struct productInfo));
tempStorage -> categoryID = tempCategoryID;
tempStorage -> categoryName[50] = tempCategoryName[50];
tempStorage -> productID = tempProductID;
tempStorage -> productName[50] = tempProductName[50];
tempStorage -> productPrice = tempProductPrice;
tempStorage -> productUnit = tempProductUnit;
tempStorage -> nextPtr = previousPtr;
previousPtr = tempStorage;
}
void display (void)
{
struct productInfo *displayItem;
displayItem = previousPtr;
char checkName[50] = "";
while (displayItem != NULL)
{
if (displayItem -> categoryName == checkName)
{
printf("IDa : %d\n", displayItem -> productID);
printf("Name : %s\n", displayItem -> productName);
printf("Price : %.2f\n", displayItem -> productPrice);
printf("Unit : %d\n", displayItem -> productUnit);
} else {
printf("Category\n");
printf("IDb : %d\n", displayItem -> categoryID);
printf("Name : %s\n", displayItem -> categoryName); //no output
checkName[50] = displayItem -> categoryName[50];
printf("Product\n");
if (displayItem -> productName == "")
{
printf("No product");
} else {
printf("IDc : %d\n", displayItem -> productID); //output have problem
printf("Name : %s\n", displayItem -> productName); //no output
printf("Price : %.2f\n", displayItem -> productPrice);
printf("Unit : %d\n", displayItem -> productUnit);
}
}
displayItem = displayItem -> nextPtr;
}
}
void deleteItem (void)
{
printf("asdads\n");
}
void updateItem (void)
{
printf("asdads\n");
}
I found that, all about char has no output, why
Regards,
Milo.