954,492 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Rename() function returning unknown vaules

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!

Creator07
Light Poster
40 posts since Nov 2008
Reputation Points: 10
Solved Threads: 2
 

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.

jencas
Posting Whiz
366 posts since Dec 2007
Reputation Points: 395
Solved Threads: 71
 
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...

Creator07
Light Poster
40 posts since Nov 2008
Reputation Points: 10
Solved Threads: 2
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You