当我运行它时,partName char 数组会打印垃圾字符。知道为什么吗?谢谢!
typedef struct {
char partName[30];
int partNumber;
float price;
int stock;
int reorder;
} inventory;
struct address{
char streetAddress[25];
char city[20];
char state[3];
char zipCode[6];
};
void GetData(){
inventory order;
address orderAddress;
printf("Enter the part number (Database Includes orders 0001 - 0005): ");
scanf("%d", &order.partNumber);
if(order.partNumber == 0001){
order.partName == "Pokeball";
order.price == 200;
order.stock == 8263;
order.reorder == 888273;
orderAddress.streetAddress == "21 Oak St.";
orderAddress.city == "Kanto Town";
orderAddress.state == "IA";
orderAddress.zipCode == "28832";
printf("Part was: %s ", order.partName);
//printf("Order was sent to: \n %s\n %s\n %s\n %s\n", orderAddress.streetAddress, orderAddress.city, orderAddress.state, orderAddress.zipCode);
}
它正在打印一些随机字符,我确信这是某个地方的简单错误。
多谢你们!