I am trying to write a program that will re-organize the data of a file that has been loaded into memory.
I already have the part of the program that will do the re-organizing, and I have already loaded the file that needs to be re-organized into memory. However, I can't get one part of the program to talk to the other part of the program.
How do I tell my program to read the in-memory file one char at a time and pass that info to the program that will do the re-organizing?
Thanks, that is a great idea. . . except I don't know how to do it. . . I know functions,
but I don't know the code to place into the function. I've been trying to use ifstream infile >> ch,
but that gives:
1 2 3 4 5 6 7 8 9 10 11 12 13
1>c:\tmci\reorganize_4\reorganize_4\reorganize_4.cpp(69):
error C2440: 'initializing' : cannot convert from
'char' to 'std::basic_ifstream<_Elem,_Traits>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> No constructor could take the source type, or constructor
overload resolution was ambiguous
1>
1>Build FAILED.
I don't know how to accomplish what I need to do. I'd give you my code, but it is 118 lines long.
Yes, I agree. However, The file in question is already in memory. I just want to update it by deleting what I don't want from what is already in memory. I thought that the process of loading it in memory also created the ifstream for that file?
Yes I agree. My problem is that I want the program that I'm writing to access the memory,
and to delete what I don't want from memory.
I do not know how to tell my program to access what is in memory.
The other part of the program will delete what I don't want to keep.
I am writing a function that will load the program into memory, and another group of functions that will delete isalpha, ispunct, ect.
I need to learn how to tell my program exactly how to read what's in memory.
all you have to do is to open the source file, find the size of the file using fseek and ftell, and read the file into a properly allocated buffer, than manipulate/remove the undesired characters in the buffer, and finally write the buffer into another file. the type of buffer can be char* or a vector of type char, so you can easily manipulate it, i.e removing, adding, replacing and so on...
I assume the file contents were buffered into some memory. That memory has an address (hopefully contiguous) and can be read from. Depending on how that buffer was created and filled you may or may not be able to alter it as-is, but may only be able to read its contents. If this is the case you can just create another buffer to mirror the changes you want.