i wanted to make a simple encryption program that you can drag a file onto the exe and it encrypts it and saves it with the same name with w/e extension i want on it.
however some pretty random stuff happens.
to list a few things going on.
1. the program works fine if run through the cmd line and given a simple file path like "test.file" that's in the same directory.
however heres where teh problem is.
when you drag a file onto it, it receives the full path "D:\My Documents\Visual Studio 2008\Projects\Levone Projects File Encryptor\LPFE quick and easy edition\test.file"
which is normally fine, but for some stupid reason i get some random ass errors.
On lines 96 and 97 (line 96 is specially wrong, but I don't like 97, either) you're just asking for trouble. Put the strings into an std::string and use that to concatenate.
thanks.
so, i don't get it. why is it that something so simple fixed it?
can you explain to me what was going wrong.
i watched the variables and other things in the debugger for.. what... 2 days now?, and didn't see anything that should have caused a problem.
yet througing it in a std::string, which is esentialy almost the same as dynamically allocating a cstring (char array) and then passing the string as a c_str() fixed everything? WTF??!!
i love computers, computer science, but i fkn HATE how random they can be soemtimes.
(or at least what seems to me like randomness?)
sizeof(argv[1]) doesn't do what you think it does.
You think it'll give you 5 if the program was called with program hello, but in reality, you're asking for the size of a pointer (since argv is a char **, argv[i] is a char *). Usually, this will be 4 or perhaps 8, but it just won't give you the actual size of the string.
If you wanted to know the size of the string, you should have done strlen(argv[1]).
In any case, std::string exists so you don't have to waste your time with error-prone things like sprintf() or strcat(). You can use them if you really want to, but you're just making things harder for yourself. I used to do that, actually, until I got tired of debugging segmentation faults and realized it wasn't worth my time.
EDIT: Oh, and under normal conditions, computers are fully deterministic.
now that i think about it. i did do a check and the sizeof(argv[1]) returned 4...
didn't think to much into it tho, just figured it must have been a place holder or something.
well, thats the point of questions. :) good thing theres people like you who can set people like me straight.