Total members 11895 |It is currently Sat Dec 21, 2024 7:24 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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?




Author:
Proficient
User avatar Posts: 280
Have thanks: 1 time

Call fscanf() in a loop until you are done reading all the integers. Use %d
as the format string.

_________________
Please recommend my post if you found it helpful


Author:
Proficient
User avatar Posts: 228
Have thanks: 0 time
Post new topic Reply to topic  [ 2 posts ] 

  Related Posts  to : Reading file with integers
 Reading the all file in php     -  
 Multithreaded File Reading     -  
 Reading and Writing To text file     -  
 Reading selected data from a source file     -  
 Reading a File Line by Line in php     -  
 Quicksort implementation C++ Code-Integers-Sorting     -  
 Encrypt/Decrypt a file from source file to target file.     -  
 Reading email in Python     -  
 help reading greyscaled image !     -  
 Parsing and Reading RSS feeds     -  









Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com