I just started learning array in C language.
1. Tryed to print out item names and prices, but getting error, While compiling no error gives, but when i run it gives error.
What did i do wrong here ?
Here is my code
#include<stdio.h>
int main(void){
float p[7]={0.55,0.8,1,1.2,0.95,0.4,0.6};
int i=1;
printf("%s%10s\n","#Item","ItemName");
for(i=1;i<8;i++){
printf("%s%13f0.2\n",i,p[i]);
}
return 0;
}
2.How i can list names? i tried with char but didnt worked well.
char n[10]={'Water','Cola','Fanta','Chokolate','Biscuit','Gum','Candy'};
this gives errl4 14 C:\Users\Erdene\Desktop\turshilt.c
[Warning] character constant too long for its type
if i change n[100] how can i list with Numbering and pricing?
like listing numbers and next to numbers Item and prices.
any advices? thanks
0not at1. So you're array index is out of bounds when it hits the value7. It should go from0to6.