Jump to content

  • Log In with Google      Sign In   
  • Create Account


read ascii value in c++


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 CyberMike   Banned   -  Reputation: 120

Like
0Likes
Like

Posted 05 January 2013 - 10:02 AM

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

 



Sponsor:

#2 SiCrane   Moderators   -  Reputation: 9491

Like
0Likes
Like

Posted 05 January 2013 - 10:12 AM

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.

#3 CyberMike   Banned   -  Reputation: 120

Like
0Likes
Like

Posted 05 January 2013 - 10:44 AM

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



#4 SiCrane   Moderators   -  Reputation: 9491

Like
0Likes
Like

Posted 05 January 2013 - 11:14 AM

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


#5 CyberMike   Banned   -  Reputation: 120

Like
0Likes
Like

Posted 05 January 2013 - 12:03 PM

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?



#6 __SKYe   Members   -  Reputation: 976

Like
0Likes
Like

Posted 05 January 2013 - 06:23 PM

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.



#7 Khatharr   Crossbones+   -  Reputation: 2914

Like
0Likes
Like

Posted 05 January 2013 - 09:21 PM

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.

#8 CyberMike   Banned   -  Reputation: 120

Like
0Likes
Like

Posted 06 January 2013 - 02:49 AM

Thanks __SKYe that helped.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS