Help with char strings
Ok... lets say that we have a char string that hold a directory, and its leght depends on user input (C:\aaa, C:\bbbb, etc)
Now i must add a "\*" in the end of that string, then replace this * with a subdirectory (C:\aaa\ccc) and then, add another "\*"
I tried it with memcpy but i got compile errors, so i need suggestions/help
Anynone avaible? thanks =]
Without any code to see exactly what errors are these, the only suggestion is...
Use std::string instead of char string
>I tried it with memcpy but i got compile errors, so i need suggestions/help
*sigh* Did it cross your mind to post your code and the errors that are thrown when you try to compile it?
The code is very big and confusing, because its not done
but here is the code snippet
and the compile error is
char * pch;
memmove (pch-DirSpec+1, arquivos[i].nome.c_str(), strlen(arquivos[i].nome.c_str()));
.\main.cpp(77) : error C2664: 'memmove' : cannot convert parameter 1 from 'int' to 'void *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
It's quiet confusing... You are using C++ strings mixed with char arrays. There is no need to. Simply use C++ strings. Forget memmove.
Two strings and replace() will do it.
I know that is not a good idea mix both tipes, its because im working with some win32api functions: FindFirstFile, FindNextFile, FindClose
Use strncpy() and strncat() then. Don't use the strcpy and strcat versions though. The 'n' versions, while not bulletproof, at least require for you to pass the size which is somewhat safer since it forces you to deal with it and better avoid out-of-bounds situations.
Check their syntax and usage here: http://www.cppreference.com/stdstring/index.html
but those functions just add more chars, they cant remove the "*"
The third argument of strncpy will say how many characters to copy to the new string. Since the '*' is the last character...
You can use C++ strings with FindFirstFile and friends. Just call c_str() like you did with memmove.
Yes, i tought about it when i went to sleep. I'll try it right now :D