I need to find the number of columns in a txt file like this:
col1 col2
34 12
24 65
This function well work in C++
#include <iostream>
#include <iomanip>
#include <fstream>
int n_colum(char name_file[]) {
int col = 0;
char c;
ifstream f;
f.open(name_file);
f >> noskipws; //I have to count the whitespace, tabs, and return
do{
f >> c;
if (c==\'t' || c==' ') col++;
}while(c!='\n'); //I consider the finish of a col when there is a '\n'
f.close();
return col+1;
}
in root the function never stop. thanks.