我想用C语言编制收银程序。使用结构我的纪录,但问题是,当我试图通过项目detail[i].name
和价格detail.[i].price
的定义的名称为循环显示的付款收据,我得到这个消息从'char *'到'char'无效转换[-fpermissive]
[错误]从“字符*”无效的转换到 '字符'[-fpermissive]
这是我的脚本
#include<stdio.h>
#include <stdlib.h>
struct item{
char name[10];
int price;
int barcode;
};
struct item detail[10]={
"item1",10,1,
"item2",20,2,
"item3",30,3,
"item4",40,4,
"item1",50,5,
"item2",60,6,
"item3",70,7,
"item4",80,8,
"item3",90,9,
"item4",100,10
};
int main(){
int ibarcode[10];int qty[10];char b[10];int price[10];int ju[10];int tot[10];
int j,i,k,grand;
char a;
printf("Cashier program\n");
for(j=0;j<10;j++){
printf("enter barcode : ");scanf("%d",&ibarcode[j]);
for(i=0;i<10;i++){
if(ibarcode[j]==detail[i].barcode){
printf("item name: %s\n",detail[i].name);
printf("price : %d\n",detail[i].price);
printf("Quantity : ");scanf("%d",&qty[j]);
tot[j]=detail[j].price*qty[j];
}
if(ibarcode[j] > 10){
printf("Barcode not valid\n");
j--;
break;
}
}
printf("\nDo you want to buy again? [Y/N] = ");scanf("%s", &a);
b[j] = detail[i].name;
ju[j] = detail[i].price;
if(a=='Y'||a=='y'){
continue;
} else {
break;
}
}
grand = 0; system("cls");
printf("\n name Kasir = Addzifi Moch G\n");
printf(" Tanggal = 03 januari 2017\n");
printf(" Jam = 14:05 WIB\n\n");
printf("+-------------------------------------------------------------------------------------------------+\n");
printf("| Barcode | name item\t\t\t| price \t\t| Quantity\t| Total |\n");
printf("+-------------------------------------------------------------------------------------------------+\n");
for(k=0; k<=j; k++){
grand += tot[k];
printf("| %d \t | %s\t | %d\t\t | %d\t\t\t| %d |\n", ibarcode[k], b[k], ju[k], qty[k], tot[k]);
}
printf("+-------------------------------------------------------------------------------------------------+\n");
printf("|\t\t\t\t\t\t\t Total Yang Harus Dibayarkan = %d |\n", grand);
printf("+-------------------------------------------------------------------------------------------------+\n");
}
'char'和'字符*'(指针)是不同的东西。您可能需要使用'&'在某处取消引用指针。 – byxor
@BrandonIbbotson不会使用&符号运算符评估类型的'char **',而不是'char'? – George
你应该告诉我们错误发生在哪一行。 (错误信息附带一个行号)。否则,我们只是在猜测。 – abelenky