Got stuck with wchar_t *argv[]

S

Sumpfman

Hi there,

i really got stuck on working with this. The user should be able to
set his usr_delay as argument and later on i want to do some math with
this (adding usr_delay to the time i get from the NetRemoteTOD
function) so i need to convert the userinput to int.


int wmain(int argc, wchar_t *argv[])
{
LPTIME_OF_DAY_INFO pBuf = NULL;
NET_API_STATUS nStatus;
LPTSTR pszServerName = NULL;

int usr_delay;

pszServerName = argv[1];

usr_delay = *argv[2] // definitely won't work!! It's just an
example for what i want to do.


nStatus = NetRemoteTOD(pszServerName,
(LPBYTE *)&pBuf);

return(0);
}


This might be quite easy but i just can't get it working :|

Thx in advance...

MFG Chris
 
J

J.L.Cooper

Sumpfman said:
Hi there,

i really got stuck on working with this. The user should be able to
set his usr_delay as argument and later on i want to do some math with
this (adding usr_delay to the time i get from the NetRemoteTOD
function) so i need to convert the userinput to int.
usr_delay = *argv[2] // definitely won't work!! It's just an
example for what i want to do.

try using the atoi function i.e.

usr_delay=atoi(argv[2]);
 
J

Jens.Toerring

Sumpfman said:
Hi there,
i really got stuck on working with this. The user should be able to
set his usr_delay as argument and later on i want to do some math with
this (adding usr_delay to the time i get from the NetRemoteTOD
function) so i need to convert the userinput to int.
int wmain(int argc, wchar_t *argv[])

What's that? Programs start with main(), not wmain(), and the
second argument to main() isn't an array of wchar_t pointers
but of char pointers. If you use non-standard stuff you better
ask in a group that deals with your system/compiler.
{
LPTIME_OF_DAY_INFO pBuf = NULL;
NET_API_STATUS nStatus;
LPTSTR pszServerName = NULL;

int usr_delay;
pszServerName = argv[1];

'pszSeverName' is of type LPSTR (whatever that is supposed to be) and
your argv[ 1 ] is of type wchar_t* - so the assignemt looks suspicious.
And if wmain() functions similarly to main() you definitely should test
if argc is at least 2 before using argv[1].
usr_delay = *argv[2] // definitely won't work!! It's just an
example for what i want to do.

Well, again assuming that wmain() is working like wmain(), then
argv[2] is a wchar_t pointer and *argv[2] would be the very first
character of that wide string, not a number. Normally, i.e. with
main(), you would use strtol() to convert the string to a number,
but for wide strings (and if you have a C99 compiler) wcstol()
probably is what you need.
Regards, Jens
 
M

Michael Mair

Sumpfman said:
Hi there,

i really got stuck on working with this. The user should be able to
set his usr_delay as argument and later on i want to do some math with
this (adding usr_delay to the time i get from the NetRemoteTOD
function) so i need to convert the userinput to int.


int wmain(int argc, wchar_t *argv[])
{
LPTIME_OF_DAY_INFO pBuf = NULL;
NET_API_STATUS nStatus;
LPTSTR pszServerName = NULL;

int usr_delay;

pszServerName = argv[1];

usr_delay = *argv[2] // definitely won't work!! It's just an
example for what i want to do.


nStatus = NetRemoteTOD(pszServerName,
(LPBYTE *)&pBuf);

return(0);
}


This might be quite easy but i just can't get it working :|

Easiest way is probably swscanf(argv[2], L"%d", usr_delay).
Have a look at the manpage of swscanf(); you also have to
#include <wchar.h>

Cheers
Michael
 
C

Charlie Gordon

Michael Mair said:
Easiest way is probably swscanf(argv[2], L"%d", usr_delay).
Have a look at the manpage of swscanf(); you also have to
#include <wchar.h>

And you forgot the &

It should read:

swscanf(argv[2], L"%d", &usr_delay);

and you should test for argc to be at least 3.

Chqrlie.
 
C

Charlie Gordon

J.L.Cooper said:
Sumpfman said:
Hi there,

i really got stuck on working with this. The user should be able to
set his usr_delay as argument and later on i want to do some math with
this (adding usr_delay to the time i get from the NetRemoteTOD
function) so i need to convert the userinput to int.
usr_delay = *argv[2] // definitely won't work!! It's just an
example for what i want to do.

try using the atoi function i.e.

usr_delay=atoi(argv[2]);

NO : atoi takes a char*, not a wchar_t *

Windows, as it seems to be the platform you are developping non standard code
for, provides some non standard alternative to this function for converting a
wide character string to a integer value.
You can also use the standard C function swscanf as explained in a different
post.

Chqrlie.
 
M

Michael Mair

Charlie said:
Easiest way is probably swscanf(argv[2], L"%d", usr_delay).
Have a look at the manpage of swscanf(); you also have to
#include <wchar.h>


And you forgot the &

It should read:

swscanf(argv[2], L"%d", &usr_delay);

Thanks, overlooked that.
and you should test for argc to be at least 3.

I am ashamed -- got this post off between two program runs
and promptly forgot the stuff I am always preaching about :-/


Thanks for the correction
Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top