Total members 10249 | Gratitudes |It is currently Thu May 17, 2012 8:32 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 2 posts ] 
Author Question
 Question subject: Reading file with integers
PostPosted: Sat Nov 08, 2008 10:50 pm 
Offline
Proficient
User avatar

Joined: Sun Oct 19, 2008 3:47 pm
Posts: 281
Has thanked: 0 time
Have thanks: 1 time

I'm trying to read a file filled with integers like this
Quote:
967 834 1000 1669 2224 1978 -142 1462 -1036 205 -1355 1781 -673 461 -1009 1495
2442 -673 -64 -1109 1104 2402 -1347 -1208 -1118 -79 1216 2218 2395 -53 226 1271
2038 369 2412 167 799 -465 394 -797 2311 1822 833 173 -836 1641 2211 -1247 1368
47 2144 -838 -743 -1463 -641 -777 241 2029 -722 -1184 1535 690 342 -1212 606
-460

and put it into an array of integer.

My idea is to read the file with getLine() method (which will result a very long
string), split it with string tokenizer with space delimiter(I did not find a
method to do this automatically like StringTokenizer in Java) and covert it one
by one to integer and put it into an array.

I find this method is very exhaustive. Any best practice for this problem? Can I
read the file delimited with space instead of per line? Any tokenizer method
without doing it manually?


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: Reading file with integers
PostPosted: Sat Nov 08, 2008 10:54 pm 
Offline
Proficient
User avatar

Joined: Sun Oct 19, 2008 3:53 pm
Posts: 229
Has thanked: 0 time
Have thanks: 0 time
Call fscanf() in a loop until you are done reading all the integers. Use %d
as the format string.


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 2 posts ] 
Quick reply


  

 Similar topics
 Image Insert in Excel File Using POI
 ASP file structure
 Search records from text file
 error closing file matlab save
 Java Object Reading
 How to download any file in jsp.
 read php file in asp and display it as html
 javascript read file
 How to make PHP form data saved into txt file
 file exists in upper level folder link

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: No registered users and 1 guest



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team