In this exercise I am using Visual Studio Community 2017 and the header file "std_lib_facilities.h" which can be found here:
http://www.stroustrup.com/Programming/PPP2code/std_lib_facilities.h
http://www.stroustrup.com/Programming/PPP2code/std_lib_facilities.h
Chapter 11 // Exercise 1
Write a program that reads a text file and converts its input to all lower case, producing a new file.
.
maam this request is not related to this exercise but rather this chapter.
ReplyDeleteits a code which outputs data into a file in binary than reads from it.
first time it works fine, but on second run there is some run time error.
basically on second run its not reading correctly from the file.
Any help will be appreciated. Thanks
code-> https://pastebin.com/USHCm0dA
I'm not sure but for me this fails at the end of the first run due to bad memory allocations. I suspect, it's reading or writing to a bad place.
Deletehey thanks for your reply can you help me with one more thing -
Deletebelow code -> ent is a class , modulebase is of type uintptr_t.
i understand whats happening here
ent* localplayer = (ent*)*(uintptr_t*)(modulebase+0x676907)
but the same code can written as
ent* localplayer = *(ent**)(modulebase+0x676907)
i understand the concept of ** . but really confused what to make of the statement, can you break it up please
Ah some lovely C. In the top one you're casting modulebase+0x676907 to a uintptr_t* then getting the contents of that and casting it to an ent*.
DeleteThen in the bottom one, ent** is a pointer to a pointer to an ent. You're casting modulebase+0x676907 directly to an ent*. *(ent**) yields ent*.
So it's basically it's getting the contents of that uintptr_t, casting it to an ent type, then returning a pointe
thanks ,
Deleteso basically what's happening is (don't mind syntax) - > modulebase+0x676907 gets casted to a ent*, than gets dereferenced once, than the contents get casted to ent* again. like -
(ent*)*(ent*)(modulebase+0x676907)
or may be i assume like this ent* -> ent* = modulebase+0x676907, and after dereferencing it is a pointer , not pointer to a pointer..
lol i am understanding but little confused at the same time too.
Pretty much! modulebase+0x676907 is being cast to an ent** and then being dereferenced once to get the first pointer. I usually like to think of the dereference operator as the "contents of" operator as it makes more sense to me. The contents of a pointer-to-pointer, is the address of the first pointer. Here's what it would look like in C++:
Delete// if modulebase+0x676907 can be cast to an ent**, then give me the contents of ent**
// the contents of ent** is ent* (which should be a pointer to the local player)
if(ent* localPlayer = *(static_cast<ent**>(modulebase+0x676907)))
{
// do thing with localPlayer
}
else
{
// cast failed, modulebase+0x676907 is not an ent type
}