Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. A tricky problem of converting to string

A tricky problem of converting to string

Scheduled Pinned Locked Moved C / C++ / MFC
databasedata-structureshelp
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anonymous
    wrote on last edited by
    #1

    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.

    P D 2 Replies Last reply
    0
    • A Anonymous

      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.

      P Offline
      P Offline
      Paolo Ponzano
      wrote on last edited by
      #2

      TCHAR is defined as typedef wchar_t TCHAR; so you can use the function below including long _wtol( const wchar_t *string ); don't understand what you doo below, hope I helped you

      P 1 Reply Last reply
      0
      • P Paolo Ponzano

        TCHAR is defined as typedef wchar_t TCHAR; so you can use the function below including long _wtol( const wchar_t *string ); don't understand what you doo below, hope I helped you

        P Offline
        P Offline
        PrashantJ
        wrote on last edited by
        #3

        Yes 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

        1 Reply Last reply
        0
        • A Anonymous

          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.

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          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

          P 1 Reply Last reply
          0
          • D David Crow

            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

            P Offline
            P Offline
            PrashantJ
            wrote on last edited by
            #5

            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

            D 1 Reply Last reply
            0
            • P PrashantJ

              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

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              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 be TBYTE 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 type TCHAR or TBYTE. 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

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups