LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-17-2011, 09:16 PM   #1
boredmuch
LQ Newbie
 
Registered: Apr 2011
Posts: 1

Rep: Reputation: 0
Post Read specifics from .txt file


(in C++)
Ok this may be tricky in understanding but here goes.
I have a txt file that has unknown # of lines of txt. Each line has the format:
"String;String;int;float" (the quotes are not there)
I use the types but there are actual words an numbers in the lines. What i need to do is read in the file, let the user specify which lines to group together to form a graph from the numbers given.
Ex;
...
Word1;Word2;3;.5
word2;Word3;4;.6
Word1;Word3;3;.4
...
If the user puts the range from (int) 2-3 and from (float) .5 - .6. The only line to place in a graph is the first line. The graph is only graphing the strings.
What im not understanding how to do is read the file and let the user specify which lines to graph. (I am in planning so no code has been written. I do not know how to read a txt file in C++ where im able to to do this)

What i have figured was that i:
Read the file
Prompt the user for a range of ints and floats
Search through the file for the lines within the range specified from the user
use those lines to graph the strings


PLEASE HELP

Last edited by boredmuch; 04-17-2011 at 09:17 PM. Reason: forgot a line
 
Old 04-17-2011, 11:51 PM   #2
stickman
Senior Member
 
Registered: Sep 2002
Location: Nashville, TN
Posts: 1,552

Rep: Reputation: 53
Not sure if your're fixed to C++, but you could parse the file pretty easily with Perl.
 
Old 04-18-2011, 12:21 AM   #3
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
To fread a file, you need to fopen it. You can traverse the file by fseek, and also fwrite it. And in the end, fclose is a must. Google the bold words.
 
Old 04-18-2011, 09:00 AM   #4
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,125

Rep: Reputation: 1260Reputation: 1260Reputation: 1260Reputation: 1260Reputation: 1260Reputation: 1260Reputation: 1260Reputation: 1260Reputation: 1260
Ask for the ranges first. Then, as you read the file, discard the points that are outside the ranges.
 
Old 04-18-2011, 09:30 AM   #5
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
homework?

I would use perl and gnuplot.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to read a txt file with C++ in linux and output it? azraelluz Programming 1 03-15-2010 08:12 PM
Read a txt file in C xeon123 Programming 3 10-21-2007 11:14 AM
How can read from file.txt C++ where can save this file(file.txt) to start reading sam_22 Programming 1 01-11-2007 05:11 PM
Read a line in a txt file with bash orgazmo Programming 5 05-03-2005 07:10 AM
Read a line in a txt file with bash orgazmo Linux - Newbie 3 05-03-2005 04:16 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration