when I run this, the partName char array prints garbage chars. any idea why? Thanks!
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);
}
It's printing some random chars, and I'm sure it's a simple error somewhere.
Thanks Guys!
The following aren't assignments . They are comparisons :
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";
To assign to integers, write
order.price = 200;
To assign to C strings, use strcpy()
et al.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.