Hi
I am having a file called Log.csv which contains 196 columns 9 of them empty and 1447 rows, I start reading the file but as I think I am facing a problem of getting the whole data, actually it gives me empty screen when print out on the screen.

I need some help in reading the csv file and put it in array because later on I have to get the date (from the first column) and min,max for some other columns.
I am really gratefull if anyone can help me.

I am going to paste 1 line from my Log.csv and then paste my code.

11/10/2004,00:00:45,190,0,13.94,346.81,201.11,18.46,32,3,47,6, ,127,230,228,228,348,128,64,64,8,6,6,50,50,50,34,34,35,6,6,6,0, ,63,230,228,230,344,66,66,66,8,6,7,50,50,50,35,36,35,6,6,6,0, ,49.41,0.00,-0.30,30.91,00,63,6,4,0, ,49.67,0.00,0.06,30.91,00,63,6,4,0, ,49.67,0.00,0.06,30.91,00,63,6,4,0, ,49.67,0.00,-0.30,30.91,00,63,6,4,0, ,49.67,0.00,-0.30,32.87,00,63,6,4,0, ,49.67,0.00,-0.30,32.87,00,63,6,4,0, ,49.94,0.00,-0.30,30.91,00,63,6,4,0, ,49.41,0.00,-0.30,30.91,00,63,6,4,0, ,49.67,0.00,-0.30,30.91,00,63,6,4,0, ,49.41,0.00,-0.30,32.87,00,63,6,4,0, ,49.67,0.00,-0.30,30.91,00,63,6,4,0, ,49.67,0.00,-0.30,32.87,00,63,6,4,0, ,49.41,0.00,0.06,32.87,00,63,6,4,0, ,49.67,0.00,0.06,30.91,00,63,6,4,0, ,

My code is

#include <iostream>
#include <fstream>
using namespace std;

float matrix_points[1447][196];
int main()
{
    std::ifstream input_file("Log.csv");
    int row(0), col(0);
    char buffer[256];
    char line[255];

    input_file.clear();
    input_file.seekg(0);

/* brings all the data in .csv file and put them in an array*/
    while(!(input_file.eof()))
    {   
        for ( col=0; col<196; col++)
        {

            if (matrix_points[row][col] != matrix_points[row][195])
                {
                input_file.getline(line, sizeof(buffer), ',');
                matrix_points[row][col] = atof(line);
                }

            else
                {
                input_file.getline(line, sizeof(buffer), '\n');
                matrix_points[row][12] = atof(line);

                }
        }

     row++;
    }
  /* for loop to print data on screen*/ 
    for (int i=0; i< row ; i++)
     for (int j=0; j< col ; j++)
        {

            if (matrix_points[i][j] != matrix_points[i][195])
                cout << matrix_points[i][j] << "  " ; 
            else
                cout << matrix_points[i][195]<< endl;
        }           


 cout << row <<endl;
 cout  << "\n\n";
  //  system("PAUSE");
    return 0;
}

Edited 3 Years Ago by happygeek: fixed formatting

As a new member to the board it will behoove you to read the instructions on how to post code to maintain the indentation protocol you wrote the code with. To do that, enclose any posted code in code tags, that is [ code ] before the code and [ /code] after the code (with out the space between the square brackets and the contents between the brackets.

As a new programmer, I encourage you to try to do things modularly. In this case I'd try to read in just the first item from the file. When I could do that, I'd try reading in the first line of the file. When I could do that, I'd try reading in the entire file.

When you get to the stage where you are reading the whole file, note that using the return of eof() as a conditional in a control statement is not the best idea---it frequently leads to undefined behaviour such as inserting the last data read in twice. You can search the board for excruciating detail if you want.

Instead, since each line has exactly 196 fields and there are exactly 1447 lines, I'd use nested for loops rather than a while loop/for loop combination use input_file.getline(line, 256, ','); as the conditional (why bother calling sizeof() each time??). Then within the loop I'd do something like this:

for(row...
  for(col...
     input_file.getline(line, 256, ','); //(why bother calling sizeof() each time??)
     matrix_points[row][col] = atof(line);

Now if I didn't know there were exactly 1447 lines, then a conditional loop would be reasonable.

row = -1;
while (input_file.getline(line, 256, ',')) //if this works there are 195 more to go on this line
  matrix_points[++row][0] = atof(line);//start a new row and 
                                       //place the sentinel value at col == 0;
  for(col = 1; ...                 //the rest go from 1 to < 196
    matrix_points[row][col] = atof(line);

In addition I'm not sure what atof() will do with a string that consists of all whitespace, so I would develop a protocol to identify a "blank" column, and not call atof() if line consisted of a single space.

Thank you Lerner for your reply, I did many things starting with reading the first item and the I cut a bit of the Log.csv file and it was working perfect with only 10 column and 1447 row, and it enabled me to get the min and max for one of the column.

#include <iostream>
#include <cstdlib>
#include <fstream>
using namespace std;

float matrix_points[10000][10];
int main()
{
    std::ifstream input_file("test.csv");
    int counter(0);
	char buffer[256];
    char line[255];

	input_file.clear();
    input_file.seekg(0);

    while(!(input_file.eof()))
	{        
        input_file.getline(line, sizeof(buffer), ',');
        matrix_points[counter][0] = atoi(line);
		input_file.getline(line, sizeof(buffer), ',');
        matrix_points[counter][1] = atoi(line);
		input_file.getline(line, sizeof(buffer), ',');
        matrix_points[counter][2] = atof(line);
		input_file.getline(line, sizeof(buffer), ',');
        matrix_points[counter][3] = atof(line);
		input_file.getline(line, sizeof(buffer), ',');
        matrix_points[counter][4] = atof(line);
		input_file.getline(line, sizeof(buffer), ',');
        matrix_points[counter][5] = atof(line);
		input_file.getline(line, sizeof(buffer), ',');
        matrix_points[counter][6] = atoi(line);
		input_file.getline(line, sizeof(buffer), ',');
        matrix_points[counter][7] = atoi(line);
		input_file.getline(line, sizeof(buffer), ',');
        matrix_points[counter][8] = atoi(line);
		input_file.getline(line, sizeof(buffer), '\n');
        matrix_points[counter][9] = atoi(line);
        counter++;
    }

      for (int i=0; i<counter; i++){
        cout <<  matrix_points[i][0] << "  " << matrix_points[i][1] << "  " << matrix_points[i][2]  << "  " 
			<< matrix_points[i][3] << "  " << matrix_points[i][4] << "  " << matrix_points[i][5] << "  " 
			<< matrix_points[i][6] << "  " << matrix_points[i][7] << "  " << matrix_points[i][8] << "  " 
			<< matrix_points[i][9]  << endl;
    }
     cout << counter<<endl;

    cout  << "\n\n";
  //  system("PAUSE");
    return 0;
}

but all the problem started when I start increasing the numbers of the column I want to read, yesterday code start only giving me a one vertical line of 0s. this why I seek anyone help. I attach the Log.csv in a zip file

Attachments

This is a simple-minded C version. You can use strtok in C++ as well.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXFLDS 200     /* maximum possible number of fields */
#define MAXFLDSIZE 32   /* longest possible field + 1 = 31 byte field */

void parse( char *record, char *delim, char arr[][MAXFLDSIZE],int *fldcnt)
{
    char*p=strtok(record,delim);
    int fld=0;
    
    while(*p)
    {
        strcpy(arr[fld],p);
		fld++;
		p=strtok('\0',delim);
	}		
	*fldcnt=fld;
}

int main(int argc, char *argv[])
{
	char tmp[1024]={0x0};
	int fldcnt=0;
	char arr[MAXFLDS][MAXFLDSIZE]={0x0};
	int recordcnt=0;	
	FILE *in=fopen(argv[1],"r");         /* open file on command line */
	
	if(in==NULL)
	{
		perror("File open error");
		exit(EXIT_FAILURE);
	}
	while(fgets(tmp,sizeof(tmp),in)!=0) /* read a record */
	{
	    int i=0;
	    recordcnt++;
		printf("Record number: %d\n",recordcnt);
		parse(tmp,",",arr,&fldcnt);    /* whack record into fields */
		for(i=0;i<fldcnt;i++)
		{                              /* print each field */
			printf("\tField number: %3d==%s\n",i,arr[i]);
		}
	}
    fclose(in);
    return 0;	
}

Hi everyone
I am absolutely stacked in the above csv file, please help:cry:

here is a c++ version that puts the strings into a 2d vector

#pragma warning(disable: 4786) // VC++ 6.0 disable warning about debug line too long
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
using namespace std;
typedef vector<string> LINE;

int main()
{
	string line;
	int pos;
	vector<LINE> array;

	ifstream in("log.csv");
	if(!in.is_open())
	{
		cout << "Failed to open file" << endl;
		return 1;
	}
	while( getline(in,line) )
	{
		LINE ln;
		while( (pos = line.find(',')) >= 0)
		{
			string field = line.substr(0,pos);
			line = line.substr(pos+1);
			ln.push_back(field);
		}
		array.push_back(ln);
	}
	return 0;
}

Hi
I do not know what to say Ancient Dragons but the code you sent giving me black screen that saying (press any key to continue) :rolleyes:

look at the code -- it doesn't print anything on the screen. All it does is read the csv file and put the strings into an array. What you do with it after that is up to you because I have no idea what you want (my crystal ball isn't working today).

:o

Hi again
I know you do not have your krystal ball with you, but if you read my first email you would know that I would like to get the date from the first column and min and max for other columns, can you give me some of your time and give me some hint on your code to :?: make it easier for me.

vectors are similar to normal arrays that relieve you with all the hassel and mistakes of memory allocations. The 2d vector is a vector of vectors. The inner-most vector contains the strings for each line, and the outer vector is the array of each line. So to get column 0 of row 0

vector<LINE> array; 

// get row 0
LINE& row = array[0];
// get column 0
string& s = row[0];

The first row (from your data file) contains column names, so the above will get the name in column 0. There are other tricks to get a column based on its name instead of a column number -- if you ever add or subtract columns in the data file, using column names instead of numbers makes your program more portable, but slightly slower to process.

string GetColData(int row_number,string ColName)
{
LINE& columnNames = array[0];
// find the collumn with the above column name
for(int col = 0; col < columnNames.size(); col++)
{
   if( ColName == ColumnNames[i] )
   {
        // get data for this column
         LINE& row = array[row_number];
        return row[col];
   }
   return "";
}

Assume myFile.txt is 1,2,3,4,5,6,7,8,9 and is located in same directory as the exe for
the program to be run.

Goal::read myFile.txt into a two dimensional 3x3 array of int and display on screen as a grid without the comma separators.

Caution: The following code has not been compiled. There may be bugs you will have
to sort out.

#include<iostream>
#include<fstream>
using namespace std;

int main()
{
  int a[3][3];                    //declare array of int
  ifstream fin("myFile.txt");  //open file
  if(!fin)                           //confirm file opened
    cout << "unable to open file;" << endl;
  else
  {
     int r, c;                        //declare counters
     char dummy;                 //to hold comma separator
     for(r = 0; r < 3; ++r)      //read file into array
       for(c = 0; c < 3; ++r)  
       { 
          fin >> a[r][c];         //read in int, >> should stop input at comma and go into 
fail state
          fin.clear();             //clear fail state;
          fin >> dummy;        //read in comma and ignore it. after reading in 9 the read 
in of EOF will also cause fin to go into a failed state and be unuseable until cleared.
      }
     
     for(r = 0; r < 3; ++r)    
       for(c = 0; c < 3; ++c)
         cout << a[r][c] << ' ' ;        //display array to screen
  }


  char ch;
  cin >> ch;
  
  return 0;
}

This nested loop system works because the contents of the file are known at compile time and is consistent throughout the file, so the container in the program can be hard coded to just the right size. The container could be 196x1447 instead of 3x3 and the algorithm could remain the same with just the details of the counters being altered to fit the project at hand.

NOTE: Even if the above works as is, without bugs, I think it would be better to use getline() to read in from file (as you did originally) and then convert input string into numerical data instead of >> with clear() and a separate read in (or ignore()) to deal with comma separator, but posting that version would be doing too much of your work for you. Also, remember, in your file, some of the fields may be blank, so you need to experiment to determine how getline() and atof() handle blank fields, so you can adjust/account for them in both the read in and analysis portions of you program.

:rolleyes:

Hi Lerner
sorry to tell you that the code sent by you can not be applied for 1447x196, I am not sure why you many know better than me. The code logically right but :?: , if you checked the log.zip file I attached previously you may get it, thanks for your help

Edited 3 Years Ago by Dani: Formatting fixed

Hi Ancient Dragon, the code looks Fab, but can you check the whole code when it brought to gother, as sometime I can see the mistake myself :o

#pragma warning(disable: 4786) // VC++ 6.0 disable warning about debug line too long
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
using namespace std;
typedef vector<string> LINE;


int main()
{
	string line;
	int pos;
	
	string GetColData(int row_number,string ColName);

	vector<LINE> array; 


	ifstream in("Log.csv");
	if(!in.is_open())
	{
		cout << "Failed to open file" << endl;
		return 1;
	}
	while( getline(in,line) )
	{
		LINE ln;
		while( (pos = line.find(',')) >= 0)
		{
			string field = line.substr(0,pos);
			line = line.substr(pos+1);
			ln.push_back(field);
		}
		
		array.push_back(ln);
	}

	return 0;
}

string GetColData(int row_number,string ColName)
{
  	int i(0);
	vector<LINE> array; 
	// get row 0
	LINE& row = array[0];
	// get column 0
	string& s = row[0];
  LINE& ColumnNames = array[0];
// find the collumn with the above column name
  for(int col = 0; col < ColumnNames.size(); col++)
  {
    if( ColName == ColumnNames[i] )
	{
        // get data for this column
         LINE& row = array[row_number];
        return row[col];
    }
   return "";
  }
}

it seems to me I did a hug mistake, sorry for this trouble, if I did any :lol: [/qoute]

Hi Ancient Dragon
I think I did something wrong with the call of the function, but I do not know what it is.

string GetColData(int row_number,string ColName);

Do you mean that line? It is not call the function -- that is a function prototype. If you want to call it you need to do something like this:

int row_number = 5;
// get value in cell at row 5, column named "Fred"
string value = GetColData(row_number,"Fred");

the call of the function causing a halt in the program. sorry for not making myself clear. I will try to figure what my mistake, and will let you know thanks ;)

Thank you so much Ancient Dragon, you help me so much. I am going to continue with my teacher requirements and I will send you always the progress of this project and I am sure will not stop from asking you to supervise me, and hopefully Iam not going stack again :o

:cheesy:

When you try to load a large number of variables into a program using static memory you can overload the stack, causing your program to fail. With an array of float sized 196x1447 you run the risk of this happening. To check for this, you can declare the array with dynamic memory rather than static memory and run the program, or check it out for yourself by progressively increasing the size of your array. If you can read the first row of the array into a 1x196 array then you should be able to use the same algorithm to read in 1447 rows of 196 fields, but you may need to use dynamic memory rather than static. As a learning exercise, if you can read in a single row of 196 fields successfully, try reading 10 rows into a 10x196 array. If you can do that try 100 rows into a 100x196 fields. Then 500 rows and so on. If you overload the stack your program will suddenly stop working at a given increment in size.

const maxRows = 1;   progressively increase this value to see what happens
const maxFields = 196;
const maxStrLen = 9; //maximum length of any given string in the array.
ifstream fin("data.txt");

char input[maxRows][maxFields][maxStrLen];  //static memory

for(r = 0; r < maxRows; ++r)
 for(int c = 0; c < maxFields; ++c)
  fin.getline(input[0][c], maxLen, ',')
 cout << endl;

If you can read in a single row of 196 fields but can't read in your entire file, then you will probably need to use dynamic memory. You can either use STL vectors as Ancient Dragon has been talking about--which is a really slick way to deal with this situation, if you are know about it and are allowed to use it; or you can do it yourself. To attempt to do it yourself you can try somehting like this:

//declaring input dynamically; it's been a while since I've used this syntax, so beware of bugs.
int row = 147;  //number of lines
int col = 19;  //number of fields
int len = 9;  //maximum number of char in any given field

char *** input;        //declare an array to store input using dynamic memory
input = new char**[row];
for(r = 0; r < row; ++r)
  input[r] = new char*[col];
  for(c = 0; c < col; ++c)
    input[r][c] = new char[len];

To add up all values in a given column from n rows

int sum = 0;
int colToAdd = whatever valid index you want to use
for(r = 0; r < n; ++r)
  sum += atoi(input[r][colToAdd]) ;

Hi Lerner
thank you for your help , ancient dragon code worked pefectly, and it is acceptable to be used. I like to know more about the code you send. I tried the static memory but it stack when the number of row 100 and the number of column as I wanted 196.

so, I tried the dynamic, I did not get the idea when you said ( to add up all the value ( that was in the last code bit)) could you clearify it more please( what ment by what ever index you want to use( can you explain it more like if I want to get the date from the second row and first col) How it will work, I am really interested in learning different ways of code.[/qoute]

Hi Ancient Dragon
I hust like to ask, why the last column is cut off when you print on screen.I think it may because the condition is to find ',' and after the last column is '\n' but I am not sure what to do about it.[/qoute]

#pragma warning(disable: 4786) // VC++ 6.0 disable warning about debug line too long
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
using namespace std;
typedef vector<string> LINE;
vector<LINE> array; 

int main()
{
	string line;
	int pos;
	string GetColData(int row_number,string ColName);

	

	ifstream in("Log.csv");
	if(!in.is_open())
		{
			cout << "Failed to open file" << endl;
			return 1;
		}
	 while( getline(in,line) )
		{
			LINE ln;
			while( (pos = line.find(',')) >= 0)
				{
					string field = line.substr(0,pos);
					line = line.substr(pos+1);
					ln.push_back(field);
					cout << field << endl;
				}
						
			array.push_back(ln);
		

		}
	
	 int row_number = 1;
    // get value in cell at row 1, column named "Date"
	string value = GetColData(row_number,"Date(dd/mm/yyyy)");
	cout << " the date is "<< value << endl;
	
	return 0;
}

/******************* Function to get the value of the Date***************/

string GetColData(int row_number,string ColName)
{
  	int i(0);
	LINE& ColumnNames = array[0];
    // find the collumn with the above column name
    for(int col = 0; col < ColumnNames.size(); col++)
		{
			if( ColName == ColumnNames[i] )
				{
					// get data for this column
					LINE& row = array[row_number];
					return row[col];
				}
		}
  return "";
}

getline() does not append the '\n' to the end of the string like fgets() does. If the last column is missing, then you probably need to add final n.push_back(field); after then end of that loop.

[qoute]
Hi again Ancient Dragon, the problem still the same.check the code please.[/qoute]

#pragma warning(disable: 4786) // VC++ 6.0 disable warning about debug line too long
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
using namespace std;
typedef vector<string> LINE;
vector<LINE> array; 

int main()
{
	string line;
	int pos;
	string field;
	string GetColData(int row_number,string ColName);

	

	ifstream in("test.csv");
	if(!in.is_open())
		{
			cout << "Failed to open file" << endl;
			return 1;
		}
	 while( getline(in,line) )
		{
			LINE ln;
			while( (pos = line.find(',')) >= 0)
				{
					string field = line.substr(0,pos);
					line = line.substr(pos+1);
					ln.push_back(field);
					cout << field << endl;
				}
			
		ln.push_back(field);	
		array.push_back(ln);
		

		}
	
	 int row_number = 1;
    // get value in cell at row 1, column named "Date"
	string value = GetColData(row_number,"Date(dd/mm/yyyy)");
	cout << " the date is "<< value << endl;
	
	return 0;
}

/******************* Function to get the value of the Date***************/

string GetColData(int row_number,string ColName)
{
  	int i(0);
	LINE& ColumnNames = array[0];
    // find the collumn with the above column name
    for(int col = 0; col < ColumnNames.size(); col++)
		{
			if( ColName == ColumnNames[i] )
				{
					// get data for this column
					LINE& row = array[row_number];
					return row[col];
				}
		}
  return "";
}

Hi Ancient Dragon
I solve the problem by doing this. check the code.[/qoute]

#pragma warning(disable: 4786) // VC++ 6.0 disable warning about debug line too long
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
using namespace std;
typedef vector<string> LINE;
vector<LINE> array; 

int main()
{
	string line;
	int pos;
	string field;
	string GetColData(int row_number,string ColName);

	

	ifstream in("test.csv");
	if(!in.is_open())
		{
			cout << "Failed to open file" << endl;
			return 1;
		}
	 while( getline(in,line) )
		{
			LINE ln;
			while( (pos = line.find(',')) >= 0)
				{
					string field = line.substr(0,pos);
					line = line.substr(pos+1);
					ln.push_back(field);
					cout << field << endl;
				}
		string field = line.substr(0,pos);
		line = line.substr(pos+1);			
		ln.push_back(field);
		cout << field << endl;
		array.push_back(ln);
		}
	
	 int row_number = 1;
    // get value in cell at row 1, column named "Date"
	string value = GetColData(row_number,"Date(dd/mm/yyyy)");
	cout << " the date is "<< value << endl;
	
	return 0;
}

/******************* Function to get the value of the Date***************/

string GetColData(int row_number,string ColName)
{
  	int i(0);
	LINE& ColumnNames = array[0];
    // find the collumn with the above column name
    for(int col = 0; col < ColumnNames.size(); col++)
		{
			if( ColName == ColumnNames[i] )
				{
					// get data for this column
					LINE& row = array[row_number];
					return row[col];
				}
		}
  return "";
}

string field = line.substr(0,pos);
line = line.substr(pos+1);
ln.push_back(field);

That isn't necessary -- the value of pos at that place is -1, so all that substr is doing is setting field = line. You can reduce the above to just one line, like this:

ln.push_back(line);

[qoute]
Hi ancient dragon, where to add that line, because if I put it after the while loop it will not change anything, still one column missing, but if I replace inside the while loop it will give an empty screen.[/qoute]

when dealing with arrays the index of the element is the key to accessing any given element within the array. The index starts at zero an goes to 1 less than the number of elements in tha array. So if you had:

int array[3][3];

for(int r = 0; r < 3; ++r)  //control row
  for(int c = 0; c < 3; ++c)  //control column
     array[r][c];

//to add the second column, which is the column with index 1 you could do this:
int sum = 0;
for(int r = 0; r < 3; ++r)  //look at all three rows
  sum += array[r][1];      //add the value of the second element in each row, that is the second column, to the value of sum each time through the loop.

And if you wanted to add the values of the 112th col (it has index 111) in a table of 1447 rows with 196 fields (aka columns) per row, you could do:

for(r = 0; r < 1447; ++r)
sum += array[r][111];

If your file has a date in the first field and floats thereafter, and you want to store all the data in the same table, then you should use a table of strings (either C style or STL strings). The first column (index 0) will be strings representing the dates, and the other 195 columns will be strings representing floats.

When you want to add up a column, determine which column you want to add up, determine it's index and run it through the loop, changing the string to float or int or whatever other data type is most appropriate, each time through the loop, and add it to some running total, compare it to previous high/low values for that column, or whatever else you want to do with it.

If you want to add up all the values on a given line, then run a similar loop add up all columns beginning with index 1, since index 0 represents a date, not a float.

Aldin: your cout statement is wrong. Load that log.csv into Excell and you will see that the last column contains all 0's.

while( getline(in,line) )
		{
			LINE ln;
			int count = 0;
			lineno++;
			while( (pos = line.find(',')) >= 0)
				{
					string field = line.substr(0,pos);
					line = line.substr(pos+1);
					ln.push_back(field);
				}
		ln.push_back(line);
		cout << line << endl;
		array.push_back(ln);

Thank you ancient dargon, sometimes you never notice how small mistake can cause huge problem. I will continue to with the rest of my assignment, Today I am having a small test before xmas.

[Qoute]
Hi Lerner
Thank you for the declaration, but the problem still with the definition of the dynamic array, because it still when running the code gives blank screen and sending error report everytime.[/qoute]

#include<iostream>
#include<fstream>
using namespace std;

//declaring input dynamically; 
int row = 1447;  //number of lines
int col = 196;  //number of fields
int len = 255;  //maximum number of char in any given field

int main()
{
  int r, c; 
  ifstream fin("Log.csv");//open file
  if(!fin)                           //confirm file opened
    cout << "unable to open file;" << endl;
  else
  {
    char *** input;        //declare an array to store input using dynamic memory
	input = new char**[row];
	for(r = 0; r < row; ++r)
	{
		input[r] = new char*[col];
		for(c = 0; c < col; ++c)
			input[r][c] = new char[len];
			cout << input[r][c] << endl;
	}
		int sum = 0;
		int colToAdd = 3 ;
		for(r = 0; r < row; ++r)
		 sum += atoi(input[r][colToAdd]) ;
		cout << "the sum" << sum <<endl;
     
  }
	 return 0;
}
This article has been dead for over six months. Start a new discussion instead.