A tricky problem of converting to string
-
Hi, Can anybody let me know the conversion function/method which will convert the TCHAR* to numeric (int/decimal). Actually I fetch the values from the database, bind it to an two dimentional array of type TCHAR. The values will look something like this. Value in database column is 100000 (numeric). TCHAR colNameArray[256][256]; I bind the database column to array colNameArray. And the value appears like this as given below. colNameArray[0][0] = 160 colNameArray[0][1] = 134 colNameArray[0][2] = 1 colNameArray[0][3] = 0 Which is actually 160 + 134*(256) + 1*(256^2) = 100000. I am looking for some method which would take colNameArray as input as convert to to a string (ascii) or to integer or to numeric. Converting to string is quite ok, so that I could convert to appropriate data types later. Thanks in advance. Prashant.
-
Hi, Can anybody let me know the conversion function/method which will convert the TCHAR* to numeric (int/decimal). Actually I fetch the values from the database, bind it to an two dimentional array of type TCHAR. The values will look something like this. Value in database column is 100000 (numeric). TCHAR colNameArray[256][256]; I bind the database column to array colNameArray. And the value appears like this as given below. colNameArray[0][0] = 160 colNameArray[0][1] = 134 colNameArray[0][2] = 1 colNameArray[0][3] = 0 Which is actually 160 + 134*(256) + 1*(256^2) = 100000. I am looking for some method which would take colNameArray as input as convert to to a string (ascii) or to integer or to numeric. Converting to string is quite ok, so that I could convert to appropriate data types later. Thanks in advance. Prashant.
TCHAR is defined as
typedef wchar_t TCHAR;
so you can use the function below includinglong _wtol( const wchar_t *string );
don't understand what you doo below, hope I helped you -
TCHAR is defined as
typedef wchar_t TCHAR;
so you can use the function below includinglong _wtol( const wchar_t *string );
don't understand what you doo below, hope I helped youYes I could have used _wtol if I was able to read the number as a string, but I am not able to see the number as string as explained in my question above. So I am actually looking for a method to first convert the value to string or w_string then go on to convert to numeric. - Prashant
-
Hi, Can anybody let me know the conversion function/method which will convert the TCHAR* to numeric (int/decimal). Actually I fetch the values from the database, bind it to an two dimentional array of type TCHAR. The values will look something like this. Value in database column is 100000 (numeric). TCHAR colNameArray[256][256]; I bind the database column to array colNameArray. And the value appears like this as given below. colNameArray[0][0] = 160 colNameArray[0][1] = 134 colNameArray[0][2] = 1 colNameArray[0][3] = 0 Which is actually 160 + 134*(256) + 1*(256^2) = 100000. I am looking for some method which would take colNameArray as input as convert to to a string (ascii) or to integer or to numeric. Converting to string is quite ok, so that I could convert to appropriate data types later. Thanks in advance. Prashant.
How about:
x = colNameArray[0][0] + colNameArray[0][1]*256 + colNameArray[0][2]*65536 + colNameArray[0][3]*16777216;
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
-
How about:
x = colNameArray[0][0] + colNameArray[0][1]*256 + colNameArray[0][2]*65536 + colNameArray[0][3]*16777216;
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
This works fine for an integer, thats true. But I could as well get a float/double, date-time, etc. So I was looking for some method which would convert this data to a string (ASCII). Later using atol, atof etc I could convert to the appropriate data type. Thanks
-
This works fine for an integer, thats true. But I could as well get a float/double, date-time, etc. So I was looking for some method which would convert this data to a string (ASCII). Later using atol, atof etc I could convert to the appropriate data type. Thanks
I mostly understand what you are asking for, but I'm not sure we are yet on the same page. By using a
TCHAR
array, the values stored in that array can range from -128 to 127. The 160 and 134 you have stored in there now won't work unless you change the type to beTBYTE
instead.TBYTE
works with values from 0 to 255. PrashantJ wrote: But I could as well get a float/double, date-time, etc. You would not be able to store 12.34 into a typeTCHAR
orTBYTE
. Out of curosity, since the database column is numeric, why not bind it to a numeric type?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen