Hey,
I am new here. I just started coding in C a couple of weeks ago. I am trying to create a simple program to input data into an array using a text file with 10 records. However, the array length is 16 and a couple of records in the middle have random generated data. Please help. Thanks.
Sample text file:
Postcode Month Year Bedrooms Price
2081 12 2007 4 795500
2180 7 2009 6 165000
2140 12 2008 5 689000
2153 3 2008 4 491500
2140 2 2010 5 886500
2005 11 2007 4 776500
2151 7 2007 5 305500
2199 12 2010 5 895000
2101 4 2010 7 389500
2176 2 2008 2 959500
//skip the header line
while (getchar()!='\n') {
}
int len = 0; //total number of records inputted
int home[][5]={{0},{0},{0},{0},{0}}; //introduce the array, [0] = postcode, [1] = month, [2] = year, [3] = bedrooms, [4] = price
int input = scanf("%d%d%d%d%d", &home[len][0], &home[len][1], &home[len][2], &home[len][3], &home[len][4]);
while (input != EOF) {
len++;
input = scanf("%d%d%d%d%d", &home[len][0], &home[len][1], &home[len][2], &home[len][3], &home[len][4]);
}
//printing inputted information into table form
print_format(1);
printf("%d", len);
printf("| %4d %02d %4d %2d %8d |\n", home[7][0], home[7][1], home[7][2], home[7][3], home[7][4]);
P.S. Also, I get an error when printing one record of an array. eg i can print fine using home[0][0] but have a problem when i use a = 0; home[a][0]; it gives a segmentation error.