Sorry, but that code does not make any sense. I have no idea what the first block of code is supposed to be doing. And in the code following the flushall call, you have made a call to strlen on a pointer returned from malloc. But the memory that it points to has not been initialised with a string, so the value you get will be either zero, or some random invalid number. You must use strlen on the source string (argv) in order to measure it. So your code should be something like:
int length = strlen(argv) + 1; // extra space for trailing null characterchar* entrenceToTheFolderBefore = (char*)malloc(sizeof(char) * length);
for (int i = 0; i < length; i++)
entrenceToTheFolderBefore[i] = argv[i];
You could use strcpy here, but perhaps your teacher has told you not to.
I dont know if i fixed it or not because Just now i saw your comment
but this is how far i got in order to get to the second frole from the first file
but for some odd reason it stopps when i do malloc
Go to ParentNow that I fixed most of the code the last part is which is the loop to find out the name of the second folder
Reminder that The argv has a path to a folder
the program is trying to exit the folder to the fodler before (succeeded)
and now at the last part trying to get the path for the second folder and the file before if it makes any sence
so for some odd reason it doesnt work
the weirder part is when i try to do puts(); on the Dir struct d_name
and it triggers break point
That is what I guessed from looking at all your posts. And that is why I suggested you stop trying random pieces of code, and go and work through some tutorials and reference guides on the basics of C and its run-time libraries. Trying to learn programming from posting questions here is really not a good idea. A few, or many, hours of serious study will serve you much better in the long term.
I have a shared storage pointer with my console application Hercules it is defined as LPVOID most of it is displayable characters but some are just hex characters
When try to construct the string with the following CString constructer
CString mystr((LPCTSTR) mysharedptr,34); tracing it in the visual studio debugger
The code goes off into some MFC code that had an assertion specifically ASSERT(FALSE)
Sorry but you are still not giving us any useful information. What exactly is the content of mysharedptr, and what assertion are you getting? It may well be that a CString is just the wrong class for whatever problem you are trying to solve.
if you need a container to hold chunks of data which might contain a NULL, CString is the wrong container. you can use a std::vector< BYTE > (or a CByteArray, if you like MFC). or you can roll your own.
Well, most data comes down to being bytes... strings just are some set of bytes that are expected to mean something (whether according to ASCII or some other wide character standard)... if you need a generic container, you can't just use something that expects what we'd refer to as a "string".
Last Visit: 21-Nov-19 8:12 Last Update: 21-Nov-19 8:12