#include <stdio.h>
typedef struct StockDetail {
char* name;
int code;
int price;
} Stock;
int main(void)
{
Stock a[200]; int i; int b;
for(i=0; i<20 ; i++ )
{
printf("Stock %i\n",i+1);
printf("Name:");
scanf("%s",a[i].name);
printf("Code:");
scanf("%i",&a[i].code);
printf("Name:");
scanf("%i",&a[i].price);
}
printf("Maximum price of the stock:");
scanf("%i", &b);
for(i=0; i<20 ; i++)
{
if(a[i].price<=b)
{
printf("%s\n",a[i].name);
}
}
}
Hi, I'm trying to implement a program that reads 20 stock details such as name, code and price and then ask the user to input a maximum price and print out the stock that cost less than the price. The code looks fine but when I tried to run it gave "segmentation fault" error line.