jeudi 5 mars 2015

Remove Parentheses and commas when reading a file and add the values to 2D array


I'm reading a text file that contains that type of data (0,9). I wanted to save the value into the 2D array. For example I try to put the condition that says while we on this line don't push those "(" "," ")" into the array, keep moving once you get a value you should save it into the [0][0] then keep moving then save other value [0][1] and finally go to the next line and repeat the process.



int const N = 10;
int const C= 2;

char *c ="(";
char *c_1 =",";
char *c_2 =")";

int array[N][C];
ifstream file;
file.open("file.txt");
int index = 0;
int index2 = 0;

// if((first_char == '(') && (second_char == ',') && (third_char == ')'))
if(!file.eof)
{


for(index ; index < N; index ++){
for(index2;index2 < C; index2++){
file >>array[index ][index2];
}} // this where the nested loop end
}



// if((first_char == '(') && (second_char == ',') && (third_char == ')')) I tried to use something like that to remove them but it was not working.. Any help please





Aucun commentaire:

Enregistrer un commentaire