我正在尝试运行一个程序,该程序在 c 中实现具有结构的函数......这是:
#include<stdio.h>
#include<conio.h>
struct store
    {
    char name[20];
        float price;    
        int quantity;
    };
struct store update (struct store product, float p, int q);
float mul(struct store stock_value);
    main()
{
    int inc_q;
    float inc_p,value;
    struct store item = {"xyz", 10.895 ,10};  //## this is where the problem lies ##
    printf("name    = %s\n price = %d\n quantity = %d\n\n",item.name,item.price,item.quantity);
    printf("enter increment in price(1st) and quantity(2nd) : ");
    scanf("%f %d",&inc_p,&inc_q);
item = update(item,inc_p,inc_q);
    printf("updated values are\n\n");
    printf(" name       = %d\n price      = %d\n quantity    = %d",item.name,item.price,item.quantity);
    value = mul(item);
    printf("\n\n value = %d",value);
}
struct store update(struct store product, float p, int q)
{
    product.price+=p;
    product.quantity+=q;
    return(product);
}    
float mul(struct store stock_value)
{
    return(stock_value.price*stock_value.quantity);
}  
当我初始化struct store item = {"xyz",10.895,10} 时; 成员没有存储值,即在成员中使用此(结构存储项):
- item.name应该是"xyz" , 
- item.price应为10.895, 
- item.quantity应该是10; 
但除了item.name =xyz 其他成员采用自己的 垃圾 值..我无法理解这种行为......我正在使用 devc++(带有 mingw 的 5.4.2 版)......
我遇到问题是因为我使用 char name[20] 作为 struct store 的成员吗???
有人请帮助删除我的代码中的错误..尽快回复