reading and printing arrays

Hello, I am new to c++ and I have to creat a program that Reads in an unknown number of records from a file {prepare your tables to handle a maximum of 50 records}. However the actual number of records on the file is not known in advance. Write a C++ program that reads and stores the record in a set of parallel arrays. Sort (use the bubble sort) the records by item number in ascending order. Then print the inventory array in the format presented below. Write the report to and output file instead of to the screen. A Sample data file was provided to me already. I attempt to first read and print out the array from the file he gave me and it complied. however it did not print out the array. Could someone explain what the problem is

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
  #include <iostream>
#include <fstream>

using namespace std;

 


#define NUM_READ_LINES 16
  int item_Number[50];
  char description[20];
  int coh[50];
  int case_capacity[50];
  float item_price[50];
  int yr[50];
  int month[50];
  int day[50];
  int yr_2[50];
  int month_2[50];
  int day_2[50];
  int min_stock;
  char thearray;
 

int main() {

   

  char thearray[NUM_READ_LINES][100];

    int counter = 0;

 

   

    ifstream inFile("c:\\list.txt",ifstream::in);

 

    

    if (inFile.good()) {

 

        

        while (!inFile.eof() && (counter < NUM_READ_LINES)) {

          inFile.getline(thearray[counter],100);

            counter++;
    }

 

        

        for (int i = 0; i < counter; i++) {

            cout << item_Number[i] << description[i] << coh[i] << case_capacity[i] << item_price[i] << yr[i] << month[i] << day[50] << yr_2[50] <<month_2[50] << day_2[50] << min_stock << endl;

        }

    }

 
    inFile.close();
    


    return 0;

}

here is what the file contained
769 Beets 012 036 1.23 2016 01 12 2016 05 05 010
876 Beans 015 020 2.34 2016 01 02 2016 09 09 005
900 Greens 024 010 1.89 2016 01 02 2015 01 01 019
512 lentels 010 012 3.90 2016 04 02 2013 04 23 004
428 rice 020 050 3.67 2016 01 17 2012 12 12 024
500 Tissue 010 010 3.98 2016 09 09 2016 11 11 025
611 Peas 100 012 2.98 2016 12 27 2009 11 10 005
691 Orka 099 015 1.08 2016 09 18 2015 11 11 019
319 sugar 012 005 6.45 2016 10 23 2016 02 02 005
499 chips 040 010 1.99 2016 10 10 2016 05 05 027
510 cokes 099 050 1.89 2016 11 11 2016 09 09 019
550 Bread 018 010 3.45 2016 12 12 2016 19 19 011
775 dog food 012 020 2.89 2016 01 08 2016 09 09 010
773 Cat food 012 020 1.90 2016 02 01 2015 08 09 011
790 Kitty litter 005 010 5.90 2016 03 01 2015 07 07 003
780 Paper Plates 019 040 1.00 2016 08 08 2015 06 06 018

First u have to fill the array named item_number, description and then display it .
it will be two dimensional array to fill the entire data item_description[16][50]

i mean u can do something like this just try it .
Since the data is separated by space u can search for the space and the fill the data in different array.
for (int i = 0; i < counter; i++)
{
int c=0;
for (int j=0;j<100;j++)
{

if (thearray[i][j]==' ')
c++;
if (thearray[i][j]!=' ' && c==0)
item_Number[i][j]=thearray[i][j];

else
description[i][j]=thearray[i][j];

}

}
}
Last edited on
Topic archived. No new replies allowed.