Current location: Hot Scripts Forums » Programming Languages » C/C++ » reading numbers from a text file


reading numbers from a text file

Reply
  #1 (permalink)  
Old 02-15-04, 12:36 AM
ASHRAF ASHRAF is offline
Newbie Coder
 
Join Date: Jan 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
reading numbers from a text file

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
Reply With Quote
  #2 (permalink)  
Old 02-16-04, 04:31 PM
hyjacked hyjacked is offline
Wannabe Coder
 
Join Date: Nov 2003
Location: New Brunswick, Canada
Posts: 174
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by ASHRAF
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.
Code:
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.
__________________
hyjacked
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP code to edit a text file mdhall Script Requests 12 12-23-10 04:03 AM
How to write a php script to load a text file into a table automatically? xmxpcom PHP 2 02-12-04 08:37 AM
picking random entries with a filter... Double selection problem dsumpter PHP 7 11-16-03 07:19 PM
Editing a text file. cjh_60 PHP 1 10-14-03 03:59 PM
Writes to a text file gamextremer2003 JavaScript 4 09-11-03 09:43 AM


All times are GMT -5. The time now is 01:21 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.