
Originally Posted by
magicyte
It is actually all too confusing. The only way I can fix the script is if I have every single bit of code there is, just to understand it all (the code, that is). Alternatively, start over. I understand what the code is supposed to do, just not HOW it does it. If you could try to compile the code again and tell me the exact errors the compiler gives you, I may be able to understand what is wrong. All in all, starting over would be easiest.
Well, the rest of the code is only a class to modify the text input. There are also no compiler errors-- the problem is that the first block, namely this:
Code:
ifstream file_in ("test.txt");
ofstream file_out ("enc.txt");
pos = 0;
file_in.seekg(0, ios::end);
len = file_in.tellg();
ending = len;
file_in.seekg(pos, ios::beg);
while(len > 0){
if(len > 350){len = 350;}
text = new char[len];
file_in.read(text, len);
file_out << text;
pos = file_in.tellg();
file_in.seekg(pos+len, ios::beg);
len = ending - pos;
}
file_in.close();
file_out.close();
Somehow reads in some additional giberish after the file ends, and the second block, namely this:
Code:
file_in.open("enc.txt", ios_base::in);
file_out.open("unenc.txt", ios_base::out);
pos = 0;
file_in.seekg(0, ios::end);
len = file_in.tellg();
ending = len;
file_in.seekg(pos, ios::beg);
while(len > 0){
if(len > 350){len = 350;}
text = new char[len];
file_in.read(text, len);
file_out << text;
pos = file_in.tellg();
file_in.seekg(pos+len, ios::beg);
len = ending - pos;
}
file_in.close();
file_out.close();
is an infinate loop for some reason. I agree that starting over is probably the best solution, but I have done that at least five times and I have no idea where to start. Do you have any suggestion?
Three last things: One-Did you make the code? Two-Do you not want me to see the whole code because you are afraid of me stealing it (I WILL NOT STEAL THE CODE. HONEST.) Three-If it is VERY IMPORTANT, try to get it copyrighted.
1) Yes, otherwise it would probably work
2) No, it's nothing like that. However, the software is for security purposes so I don't want to show it. And at any rate the class shouldn't be needed-- it's basically irrelevant to the problem. (When text is read in from a file, that class modifies it before sending it to the output file.) Without the file I/O, the class works perfectly. 3) It's not that important.
And one last thing: Are you a black belt??
Yes
3rd Dan in Tae Kwon Do.
Edit: In the second block, the reason for the infanite loop is that this line:
Code:
pos = file_in.tellg();
Always sets pos to-1 (thus pos - the file length is 1, which the loop thinks is another character to read in so the loop starts again), but I don't know why that is.
Bookmarks