1 (edited by fhd_21 2006-06-03 18:54)

Topic: Need help in C++

Hi,

How can I convert a character after reading it from a file through an ifstream to the program into integers?
Note that the file contains 32 line, each line contains 32 number (52, 65, 0, 8, 123, ect). separated by a space?
so I'll have to read the file line by line by the function getline, then spot the integrs in each line by A.find function and store each int an an array called whatever?

CAN ANYBODY PLEASE HELP?!

فهد

2 (edited by SirNotApearingOnThisForum 2006-06-12 16:32)

Re: Need help in C++

Well, what do you need help with specifically?  All you have to do is go through each line, picking out the integers as you go and storing them in a 32*32 sized array.  Eg.

int whatever[32][32] = { 0 };

void retrievevalues(char *line, int index)
{
    int i;
    char *p;
    
    for(i = 0, p = line; i < 32 && *p; i++)
    {
        while(!isdigit(*p) && *p) p++; //find int
        
        if(*p) whatever[index][i] = strtol(p, &p, 10); //convert int and move pointer
    }
    
    return;
}

//get lines, etc...