Hello,

I was doing a test Win32 Project. I am using the standard rename() function under cstdio. My program was not working. So, while tracing, I got the return value of rename function as -1.

I have not seen anywhere, rename(0 function returning -1. Could anyone tell me what's wrong.

Code:

int flag = rename((char *)OldName, (char *)NewName);
\\OldName and NewName are of type wchar_t
\\flag returns -1

Thanks in advance!

Recommended Answers

All 2 Replies

Member Avatar for jencas

wchar_t means wide character. You can't convert a wchar_t to a char by "brute force casting" it. You have to call an appropriate function to convert it. Take a look at wcstombs_s(), additionally there are some Macros for conversion, for example CA2CT.

commented: Thanks a lot for the valuable info +1

wchar_t means wide character. You can't convert a wchar_t to a char by "brute force casting" it. You have to call an appropriate function to convert it. Take a look at wcstombs_s(), additionally there are some Macros for conversion, for example CA2CT.

Oh! OK.. I got wcstombs to work. The problem I do while coding is type cast things directly if the complier shows the error - function cannot convert parameter x from xxxx to xxxx.

Thanks for the help dude! Respect to you...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.