Results 1 to 4 of 4
I am creating a program that needs to read each single character of a text file (ascii) and convert it to a number. Is there a way I can do ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 12-27-2013 #1
C++ read individual characters/lines in a file
If I am not being very clear, please ask, I really want to make this program. Thanks!
- 12-27-2013 #2
Undoubtedly, yes, a loop of some sort will be needed somewhere.
I understand that homework-type questions are not answered on here very often, though, for the very reason that they are meant to be your work, not someone elses. Also, one of the best ways to learn is to nut it out for yourself.
Not to say of course that no-one will help. I think most people would like to see you give it a good shot first, maybe try quite a few methods, and only come back here if you are truly stuck, but not at the beginning of the task.
- 12-28-2013 #3
Is it just one long string of a text file? Or is each character on a different line?
Either way is pretty simple, but can take different approaches.
If it is just one long string of characters, read them into a character array and work with it there (hint: a string can be used as a char array). If it is one on each line, then setup a loop and read each line separately with getline, do the comparison and move on.
And of course, there are several other ways to do it, those two were on the top of my head.
Linux User #376741
Code is Poetry
- 12-28-2013 #4
Also look at an ASCII chart you'll see part of your solution done for you.