PDA

View Full Version : reading numbers from a text file


ASHRAF
02-15-04, 01:36 AM
Hello

I have a text file in this form:

This file is a text file
Please help me in it
My name is ashraf
AR 12 34 56 45
FV 14 15 16 17
DC 33 43 22 11

I need to read the numbers only and ignore all the text
can someone help me to do that please.

thanks in advance.
ashraf

hyjacked
02-16-04, 05:31 PM
Hello

I have a text file in this form:

This file is a text file
Please help me in it
My name is ashraf
AR 12 34 56 45
FV 14 15 16 17
DC 33 43 22 11

I need to read the numbers only and ignore all the text
can someone help me to do that please.

thanks in advance.
ashraf

if there will only ever be letters in the first column, then read in the line, search the string by spaces, and don't save the first value.

not exact C/C++ code but close.

string temp="";
int index=0;
int len=0;
int values[4];

while(!file.eof)
{
temp = file.readline();
index = temp.find(" ", 1);

for(i=0;i<4;i++)
{
len = file.len(); // get length of file
temp = temp.substr(index, len); // get rid of letters and spaces at start
index = temp.find(" ", 1); // get position of next space
values[i] = ctoi(temp.substr(0, index)); // save data between start of string and nextspace.
}
}


I doubt the code will work, but it should give you a good start on how to tackle the problem.

Best of luck, feel free to write back with problems if you have any.