I'm trying to debug a 3rd party library here which contains the following line:-
where 'filePath' is a narrow character string and 'audioEssence->usable_file_path' is of type wchar_t*
When I run this code in my debugger the resulting string in 'audioEssence->usable_file_path') comes out looking like garbage. Two questions...
1) Should L"%s" work here or is it only intended for string literals?
2) Is the programmer right to be multiplying strlen(filePath by sizeof(wchar_t) :confused:
[Edit...] and after a bit more testing...
2) Is the programmer right to be multiplying strlen(filePath by sizeof(wchar_t)
No, that looks wrong here. swprintf() expects the number of characters to print - not the number of bytes.
1) Should L"%s" work here or is it only intended for string literals?
Yes, it looks like that'll work - but only if filePath is already in wide character format. It doesn't seem like swprintf() supports a mixture of wide character strings and narrow character strings. Am I interpreting that correctly ?
Code:
swprintf( audioEssence->usable_file_path, (strlen(filePath) * sizeof(wchar_t)), L"%s", filePath );
When I run this code in my debugger the resulting string in 'audioEssence->usable_file_path') comes out looking like garbage. Two questions...
1) Should L"%s" work here or is it only intended for string literals?
2) Is the programmer right to be multiplying strlen(filePath by sizeof(wchar_t) :confused:
[Edit...] and after a bit more testing...
Quote:
2) Is the programmer right to be multiplying strlen(filePath by sizeof(wchar_t)
Quote:
1) Should L"%s" work here or is it only intended for string literals?