Handling .csv to array

What I need to do is read in the following (from .csv), calculate something [float estimate] using the numbers (before %) at the end of the string:

2010,9265406,7255262,U926214288131,16/04/94,F,M ,4.3,4.7,5.0,4,4,4,PA,50,Art & Design,1 %,1 %,1 %,1 %,10 %,46 %,35 %,8 %,1 %,89 %,43 %

I need to output the result of the calculation, float estimate, for each line. The only other bit of the string we need is the UPN which I have emboldened.

The UPN begins with any uppercase character (I say this as we can't use ignore up to "U").

Obviously there are various options for how to handle the data but the output file only needs to be UPN, estimate and in a .csv.

Whats the most efficient way to do this?

Code (rough!) so far... and I've omitted first line as you will see

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>
#include<sstream>
#include<string>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>



using namespace std;

string import[140][30];
int columnnumber=0;
bool firstline1=false;
string line;
int rownumber=0;
stringstream tbp;
stringstream firstline2;
string record;
ifstream myfile ("TestDataFile.csv");

int main() {


    if (myfile.is_open()){

        while (myfile)
        {
            while(firstline1==false)
            {

                getline (myfile,line);
                firstline2 << line;
                firstline1=true;
            }
            getline (myfile,line);
            tbp <<line;
            tbp.ignore(100,'');
            /*tbp.ignore(100,'%');*/
            if(firstline1==true){
                while(getline(tbp,record,','))
                {

                    import[rownumber][columnnumber]=record;
                    columnnumber++;
               
                rownumber++;
                columnnumber=0;
                tbp.clear();
                }}
            else
            {
                tbp.clear();
                firstline1=true;
            }

        }
    }
    myfile.close();


    while(columnnumber<4000){

        cout<<import[0][columnnumber];
   
       
            columnnumber++;
       
       



    }
    return 0;
} 


Many thanks for all advice,

Ad1234
Have I posted badly here? I had no replies which seems unusual?
Thanks
Ad1234
It's quite possible nobody has an answer for you; I have no idea in heck how to read a binary-formattted csv file. (Binary files are files with any form of formatting; that is a file that is not made up entirely of text)
However, I'll just caution you now to take a look at the article on multidimensional arrays; depending on your skill level that may have some relevant warnings for you to take into account.
yea I don't quite see the need to increment columnnumber then make it zero 2 lines below, one statement needs to be removed lines 46, 49
What is a float estimate - is it the average?
So in the line you have shown us - you want the average of 1 ,1 ,1 ,1 ,10 ,46 ,35 ,8 ,1 ,89,43 ??
Is this something that has to be done in C++? For example, if you are just interested in generating some statistics or the like, Perl and a nice regular expression could save the day!
Topic archived. No new replies allowed.