Click to See Complete Forum and Search --> : Simple conversion question


Illusioned
June 29th, 1999, 01:00 AM
How would I convert an unsigned short to an INT?
How would I convert a string to an unsigned short?

I don't have VC++, but I figured somone could help me here.. I have borland C++ 4.52.. Is there a predefined function for this? Is their possibly an API function for this conversion??

Please help - Anything would be greatly appreciated


Illusioned

Fabi Pantera
June 29th, 1999, 01:06 AM
Hope this helps you.
unsigned short nYourShort;
int nmyInt = (int)nYourShort;
For the string. A string is actually a list of caracters(unsigned short or whatever for Unicode). How do you want to translate a list into a double byte value. Maebe i don't well understand you.
Let me know if this help you,
Best regards,
Faby

Fabi Pantera
June 29th, 1999, 01:08 AM
Sorry for the previous. I think i understand your message Try with "atoi" function.
Regards,
Faby

Illusioned
June 29th, 1999, 01:12 AM
Im mainly interested in the conversion of the unsigned short to an int. I've used the method you've desribed already [ myInt = (int)myShort ]and I get a protection fault.. Any other clues?

Illusioned

Fabi Pantera
June 29th, 1999, 01:16 AM
It's something wrong with your code. This should be working. There are no API fuctions whitch make this conversion. Or maebe is a Borland error. Did you tryed to rebuild all?
Regards,
Faby

Illusioned
June 29th, 1999, 01:25 AM
Yes, and I've found it was not your conversion that was causing the error it is the next few lines... What Im trying to do is get the separate parts of the system time from the GetSystemTime API.. heres a peice of the code.. any Ideas?

SYSTEMTIME CurTime;
GetSystemTime(&CurTime);
char *TempStr;
char *TimeCPTN;
int myInt;
myInt = (int)&CurTime.wHour;
TempStr = itoa(myInt, TempStr, 10);
strcat(TimeCPTN, TempStr); //<-- Causes the GPF
strcat(TimeCPTN, ":");




Also when I do the conversion myInt = (int)&CurTime.wHour; It returns a Giant number thats seems to change each 100'th of a second... Im so new at all this.. any Ideas?


Illusioned

Fabi Pantera
June 29th, 1999, 01:31 AM
This is an pointer
myInt = (int)&CurTime.wHour;
Try this :
myInt = (int)CurTime.wHour;

Faby

Illusioned
June 29th, 1999, 01:40 AM
That seems to have fixed the problem (: Now the only problem Im having is for hour it's returning 6 when it should be returning 2, but im sure I can figure that out my self.. Thanks alot, you were a great help

Illusioned

eric33
June 29th, 1999, 02:18 AM
I read your code with little late but for me it seems to have a big problem.

I think the reponse to prefer 'CurTime.wHour' than '&CurTime.wHour' is right but do not explain the GPF. Because not matter the value you give to myInt itoa and strcat works well.

But one little question. Is your code exactly has described.
Because for me TempStr and TimeCPTN point on nothing and you cannot use these variables with itoa or strcat.

This will work better :


SYSTEMTIME CurTime;
GetSystemTime(&CurTime);
char TempStr[20]; // 20 is an example here
char TimeCPTN[20];
int myInt;
myInt = (int)CurTime.wHour;
TempStr = itoa(myInt, TempStr, 20);
strcat(TimeCPTN, TempStr);
strcat(TimeCPTN, ":");




Hop this help