943,793 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 842
  • C++ RSS
Jun 22nd, 2009
0

Rename() function returning unknown vaules

Expand Post »
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:
cpp Syntax (Toggle Plain Text)
  1. int flag = rename((char *)OldName, (char *)NewName);
  2. \\OldName and NewName are of type wchar_t
  3. \\flag returns -1

Thanks in advance!
Reputation Points: 10
Solved Threads: 2
Light Poster
Creator07 is offline Offline
40 posts
since Nov 2008
Jun 22nd, 2009
1

Re: Rename() function returning unknown vaules

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
Reputation Points: 395
Solved Threads: 71
Posting Whiz
jencas is offline Offline
362 posts
since Dec 2007
Jun 22nd, 2009
0

Re: Rename() function returning unknown vaules

Click to Expand / Collapse  Quote originally posted by 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.
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...
Reputation Points: 10
Solved Threads: 2
Light Poster
Creator07 is offline Offline
40 posts
since Nov 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Deleted Repeated Array elements not working
Next Thread in C++ Forum Timeline: Editing txt files with c++





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC