read ascii value in c++

Started by
6 comments, last by CyberMike 11 years, 3 months ago

Hi

following this: http://www.cpptutor.com/ascii.htm

I want to read a file with for example this content "TEST4testingTest"

The problem is how to change the value E but to be able to revert it later again.

So I've tried to save as int but I only get errors.

Many thanks

Advertisement
You're going to have to be more explicit about what you mean by "change the value E but to be able to revert it later again". If you have code that you've tried, then try posting that code along with the errors you've received.

while(!inFile.eof())
{

char NewByte, Byte;

// Out old byte is recieved from the file
Byte = inFile.get();

// If the file that we are reading has an error, turn 0
if (inFile.fail())
return 0;
if ((int)Byte == 56){
NewByte = 126;

Using if- and ofstream this doesn't work. Basically I want to change the value, save for later reopening. Later reopen and changing back to see the original text.

Probably my conversions are not correct as without manipulating all is fine?

Many thanks

Define "doesn't work".
... then try posting that code along with the errors you've received.

I don't get any errors. It compiles ok but comparing the files after changing back is not identical. That's exactly what I'm investigating now. How would that look by changing "E" and not the value?

Your explanation makes no sense, and your code even less.

First if the char you read is 56, you set NewByte to 126. That is useless, as NewByte is a local variable and will be lost as soon as the while() loop ends.

Also there's no need to cast the Byte variable to int, you can compare the char variable to 56, or even the char it represents by using '8' instead of 56.

And using "E" is not the same as using 'E': 'E' is a single char, but "E" actually is a null-terminated string formed by the characters 'E' and '\0'.

Try to make a clearer explanation, and posting the full code would also help.

Please use code tags when posting code and please post the whole body of the code which may be responsible for the error.

An 'error' is not necessarily a compiler error - it's a general term for anything that your program is doing that you don't want it to or anything that it's not doing that you do want it to.

To clarify, my understanding right now is that you're wanting to:
  • read a value from a file
  • store that value in memory
  • change the value in the file (while still holding the original value in memory)
  • close the file
  • re-open the file later
  • restore the original value
Can you post the whole body of code that is trying to do this? Also, is there anything I'm missing or misunderstanding here?
void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.
Thanks __SKYe that helped.

This topic is closed to new replies.

Advertisement