You are here:

C++/How to differentiate integers and alphabets


Dear Sir,
I have previously asked a question on how to differentiate integers and alphabets when reading from a .txt file. thank you so much for your kind advise. But too bad my previous question was too vague. Below is the sample .txt file which i would read from.
Data Logged on September 16, 2006, at 15:09:27


Log_Mode = 2
Sampling_Factor = 8
Defined_Sample_Size = 4000
Captured_Sample_Size = 4000
Delay_Sample = 0
Static_Sample = 10

Smp_No.      AN_EnB_HYG   BY_Cmd_HDA   IJ_MJK_Value
0       -20001       -20000          -69
1       -20001       -20001          121
2       -20001       -20001          -90
.          .          .          .
.          .          .          .
.          .          .          .
.          .          .          .
3999        65536      1420544          305   
So what I need to do is to actually read the figures from some coloums (for e.g AN_EnB_HYG & IJ_MJK_Value)...from sample no.0 to 3999. And calculate the max, min and average for the figures under AN_EnB_HYG & IJ_MJK_Value.. Every information besides these 2 coloums of figures are redundant to me..Please advise...thanks!  

Hello Liwei, thank you for the question.

Sorry I couldn't get to this sooner, I have been extremely busy at work.

Here is what I recommend. Use strtok() to parse your file with a space as a delimeter. Every token you pop out, convert it to a number using the method atoi(). Once you parse out your file headers, strtok() should pop out all of the numbers for you 1 by 1, stopping on the spaces in between. Now that you have a char*, you can convert it to an integer with atoi(). This should solve your problem.

Please don't hesistate to ask me another question if I failed to explain something properly.

I hope this information was helpful.

- Eddie


All Answers

Answers by Expert:

Ask Experts




I can answer questions about the C++ language, object oriented design and architecture. I am knowledgable in a lot of the math that goes into programming, and am certified by I also know a good deal about graphics via OpenGL, and GUIs.


I have completed numerous games and demos created with the C++ programming language. Currently employed as a software engineer in the modeling and simulation field. I have about 7 years experience.

©2016 All rights reserved.