-
Error messages
This is a part of my code:
Code:
void openfile(void *P){
GetWindowText(dropdown,tfile,260);
file=FtpOpenFile(say,tfile,GENERIC_READ,FTP_TRANSFER_TYPE_ASCII,0);
InternetReadFile(file,file_contents,100000,&car);
InternetCloseHandle(file);
add=file_contents;
std::string::size_type pos = -1;
while((pos=add.find("\n",pos+1))!=std::string::npos){
add.replace(pos,1,"\r\n");
}
*(std::copy(add.begin(), add.end() - add.begin() < 256 ? add.end() : add.begin() + 255, file_contents)) = 0;
SetWindowText(edit,file_contents);
return;
}
And when this runs I always get illegal operation message or "abnormal program termination" message.
-
try to run in debug mode and see what line fails
-
I can't use Dev-C++ debug, because I always get BSOD then.
But I think it's about the "add.replace..." line, because when I change the 1 to 2, I don't get any errors, but the text is totally messed up(the first '\n' keep repeating).
I think you understand what I am trying to do and maybe you can give me an alternative way to do the same thing.
-
I think your problem is that the indexes get thrown off since you are adding another character to the string each iteration. Try increasing pos by 1 at the end of the loop.
Also, you can see if string is throwing any errors:
Code:
try
{
openfile();
}
catch (std::exception& error)
{
MessageBox(NULL,error.what(),"Caugh Exception:",MB_OK);
}
Gotta run :D
-
try changing
Code:
add.find("\n",pos+1)
to
Code:
add.find("\n",pos+2)
you keep removing "\n" at pos n, then you add "\r\n" at pos n, then you check again for "\n" at pos n+1 which is where the \n in the \r\n is.
-
Thanks, I didn't really need to use replace in my code...