Rename() function returning unknown vaules

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Nov 2008
Posts: 40
Reputation: Creator07 is an unknown quantity at this point 
Solved Threads: 2
Creator07 Creator07 is offline Offline
Light Poster

Rename() function returning unknown vaules

 
0
  #1
Jun 22nd, 2009
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:
  1. int flag = rename((char *)OldName, (char *)NewName);
  2. \\OldName and NewName are of type wchar_t
  3. \\flag returns -1

Thanks in advance!
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 360
Reputation: jencas is just really nice jencas is just really nice jencas is just really nice jencas is just really nice jencas is just really nice 
Solved Threads: 69
jencas jencas is offline Offline
Posting Whiz

Re: Rename() function returning unknown vaules

 
1
  #2
Jun 22nd, 2009
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.
Last edited by jencas; Jun 22nd, 2009 at 8:42 am. Reason: typo correction
If you are forced to reinvent the wheel at least try to invent a better one!

Please use code tags - Please mark solved threads as solved
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 40
Reputation: Creator07 is an unknown quantity at this point 
Solved Threads: 2
Creator07 Creator07 is offline Offline
Light Poster

Re: Rename() function returning unknown vaules

 
0
  #3
Jun 22nd, 2009
Originally Posted by jencas View Post
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...
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC