Click here to Skip to main content
15,893,904 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have generated text file containing random numbers (using for loop), and these numbers are stored in the text file in the form space number space. I need to read integers each of 10-digit (as 8210347655). I'm very headache and seeing it a very trouble, please can anyone help me.

regards...
Posted
Updated 25-Oct-13 15:14pm
v2
Comments
Sergey Alexandrovich Kryukov 26-Oct-13 0:10am    

1 solution

0) Read one character at a time
1) Append the non-SPACEs to a StringBuilder (or similar, I see now this isn't a .net question)
2) When you reach a SPACE, use Int32.TryParse on the content of the StringBuilder
3) Then set the StringBuilder's Length to zero
4) When you reach the end, do one more TryParse

Some error handling might be necessary as well.
 
Share this answer
 
v2
Comments
3bood.ghzawi 25-Oct-13 21:21pm    
Thanks dear. But StringBuilder and Int32.TryParse exist in visual studio, and i work using C under linux.
PIEBALDconsult 26-Oct-13 11:19am    
Adjust as needed. The basic algorithm reamins the same.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900