473,379 Members | 1,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

better way to read data?

I try to read a text file with format:

11 1.11111
22 2.22222
33 3.33333
....

I try to use fscanf() to read the data back. What is the better way?

Feb 7 '06 #1
5 1271
* kathy:
I try to read a text file with format:

11 1.11111
22 2.22222
33 3.33333
...

I try to use fscanf() to read the data back. What is the better way?


Depends on your criteria.

Have you tried C++ streams, like std::cin and (type) std::ifstream?

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Feb 7 '06 #2
kathy wrote:
I try to read a text file with format:

11 1.11111
22 2.22222
33 3.33333
...
And what do you expect after reading? A bunch of integers and floats?
A bunch of strings? A bunch of pairs (triples) of strings? What?
I try to use fscanf() to read the data back. What is the better way?


In C++ the use of operator>> with 'ifstream' is encouraged. Whether it
is actually better is a matter of personal preference.

V
--
Please remove capital As from my address when replying by mail
Feb 7 '06 #3
Victor Bazarov wrote:
kathy wrote:

[snip]
I try to use fscanf() to read the data back. What is the better way?


In C++ the use of operator>> with 'ifstream' is encouraged. Whether it
is actually better is a matter of personal preference.


Well, I'd say it's more than a matter of personal preference since
*scanf() are not type-safe.

char c;
int d;
scanf( "%d %c", &c, &d ); // Oops!

Whereas code with iostreams is less hazardous to your program's health
since the ellipsis is not used and since the format strings do not need
to be correlated to the arguments:

cin >> d >> c; // No oops

Cheers! --M

Feb 7 '06 #4
mlimber wrote:
Victor Bazarov wrote:
kathy wrote:
[snip]
I try to use fscanf() to read the data back. What is the better way?


In C++ the use of operator>> with 'ifstream' is encouraged. Whether it
is actually better is a matter of personal preference.

Well, I'd say it's more than a matter of personal preference since
*scanf() are not type-safe.


C++ and C are so filled with UB or IDB, that using them in general is
a certain risk, and taking such risk _is_ a matter of personal preference.
char c;
int d;
scanf( "%d %c", &c, &d ); // Oops!

Whereas code with iostreams is less hazardous to your program's health
since the ellipsis is not used and since the format strings do not need
to be correlated to the arguments:

cin >> d >> c; // No oops

Cheers! --M


V
--
Please remove capital As from my address when replying by mail
Feb 7 '06 #5
"mlimber" <ml*****@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
Victor Bazarov wrote:
kathy wrote:

[snip]
> I try to use fscanf() to read the data back. What is the better way?


In C++ the use of operator>> with 'ifstream' is encouraged. Whether it
is actually better is a matter of personal preference.


Well, I'd say it's more than a matter of personal preference since
*scanf() are not type-safe.

char c;
int d;
scanf( "%d %c", &c, &d ); // Oops!

Whereas code with iostreams is less hazardous to your program's health
since the ellipsis is not used and since the format strings do not need
to be correlated to the arguments:

cin >> d >> c; // No oops


Unless the data are not in the same order the
input statements expect. Moral: always check
for errors, whether using scanf() or operator>>().

-Mike

Feb 7 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: John | last post by:
I have over 5000 thumbnail pictures of size 5kb each. I would like to able to load all 5000 pictures and view 50 per page using mysql_data_seek(). I would like to know what are the advantages and...
5
by: Lukas Holcik | last post by:
Hi everyone! How can I simply search text for regexps (lets say <a href="(.*?)">(.*?)</a>) and save all URLs(1) and link contents(2) in a dictionary { name : URL}? In a single pass if it could....
5
by: Aaron | last post by:
Some of my db-driven web pages rarely change. They pull the exact same data every time (the table is almost read-only). Should I consider using page caching? or do i just need to turn on caching in...
14
by: Sean C. | last post by:
Helpful folks, Most of my previous experience with DB2 was on s390 mainframe systems and the optimizer on this platform always seemed very predictable and consistent. Since moving to a WinNT/UDB...
3
by: mrhicks | last post by:
Hello all, I have a question regarding efficeny and how to find the best approach when trying to find flag with in a structure of bit fields. I have several structures which look similar to ...
12
by: Jonathan Bartlett | last post by:
Just finished a new IBM DeveloperWorks article on linked lists, and thought you all might be interested. It's not an introduction -- it instead covers some of the more interesting aspects of...
3
by: Chris | last post by:
I have a modal (yes it must be modal) web page. I do this by having an empty frame that points to my main page (so that I can repost without new popups) I have to pass data to the child page from...
43
by: Rob R. Ainscough | last post by:
I realize I'm learning web development and there is a STEEP learning curve, but so far I've had to learn: HTML XML JavaScript ASP.NET using VB.NET ..NET Framework ADO.NET SSL
6
by: Anton Vredegoor | last post by:
Since a few days I've been experimenting with a construct that enables me to send the sourcecode of the web page I'm reading through a Python script and then into a new tab in Mozilla. The new tab...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.