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. Can someone help with varible type problem

Can someone help with varible type problem

Scheduled Pinned Locked Moved C / C++ / MFC
help
8 Posts 6 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.
  • S Offline
    S Offline
    ScarberryProd
    wrote on last edited by
    #1

    ok i have a header file and this is the error i get: error C2664: 'sprintf' : cannot convert parameter 1 from 'char' to 'char *' Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast and here is my code, im stumped: #define BAUDRATES_C #include "stdafx.h" #include "BaudRates.h" typedef struct{ char BaudRate[15]; unsigned char Length; }BaudRateType; const BaudRateType BaudRateList[16] = { {"110", 3}, {"200", 3}, {"300", 3}, {"1200", 4}, {"2400", 4}, {"4800", 4}, {"9600", 4}, {"14400", 5}, {"19200", 5}, {"28800", 5}, {"38400", 5}, {"56000", 5}, {"57600", 5}, {"115200", 6}, {"128000", 6}, {"256000", 6}, }; void PopulateBaudDropdown(CComboBox *box) { int i; for(i=0;i<16;i++) { box->AddString((char*)&BaudRateList[i].BaudRate); } } char ReadBaudDropdown(CComboBox *box) { int baudindex; char rate; baudindex = box->GetCurSel(); sprintf(rate,"%d",BaudRateList[baudindex].BaudRate); return rate; } please help, thank you --------------------- And Like The Wind Our Hero Vanishes Off Into The Distance...

    L B B R R 5 Replies Last reply
    0
    • S ScarberryProd

      ok i have a header file and this is the error i get: error C2664: 'sprintf' : cannot convert parameter 1 from 'char' to 'char *' Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast and here is my code, im stumped: #define BAUDRATES_C #include "stdafx.h" #include "BaudRates.h" typedef struct{ char BaudRate[15]; unsigned char Length; }BaudRateType; const BaudRateType BaudRateList[16] = { {"110", 3}, {"200", 3}, {"300", 3}, {"1200", 4}, {"2400", 4}, {"4800", 4}, {"9600", 4}, {"14400", 5}, {"19200", 5}, {"28800", 5}, {"38400", 5}, {"56000", 5}, {"57600", 5}, {"115200", 6}, {"128000", 6}, {"256000", 6}, }; void PopulateBaudDropdown(CComboBox *box) { int i; for(i=0;i<16;i++) { box->AddString((char*)&BaudRateList[i].BaudRate); } } char ReadBaudDropdown(CComboBox *box) { int baudindex; char rate; baudindex = box->GetCurSel(); sprintf(rate,"%d",BaudRateList[baudindex].BaudRate); return rate; } please help, thank you --------------------- And Like The Wind Our Hero Vanishes Off Into The Distance...

      L Offline
      L Offline
      Lada
      wrote on last edited by
      #2

      Hi, I've found two mistakes in your code: in the line: box->AddString(**(char*)&**BaudRateList[i].BaudRate); make this change: box->AddString(BaudRateList[i].BaudRate); and in the line: sprintf(rate,"%d", BaudRateList[baudindex].BaudRate); make this change: sprintf(rate,"%s", BaudRateList[baudindex].BaudRate); Lada

      S 1 Reply Last reply
      0
      • L Lada

        Hi, I've found two mistakes in your code: in the line: box->AddString(**(char*)&**BaudRateList[i].BaudRate); make this change: box->AddString(BaudRateList[i].BaudRate); and in the line: sprintf(rate,"%d", BaudRateList[baudindex].BaudRate); make this change: sprintf(rate,"%s", BaudRateList[baudindex].BaudRate); Lada

        S Offline
        S Offline
        ScarberryProd
        wrote on last edited by
        #3

        umm i changed it and still got the same error ty --------------------- And Like The Wind Our Hero Vanishes Off Into The Distance...

        L 1 Reply Last reply
        0
        • S ScarberryProd

          umm i changed it and still got the same error ty --------------------- And Like The Wind Our Hero Vanishes Off Into The Distance...

          L Offline
          L Offline
          Lada
          wrote on last edited by
          #4

          I overlooked another mistake. change char ReadBaudDropdown(CComboBox *box) { int baudindex; char rate; baudindex = box->GetCurSel(); sprintf(rate,"%d",BaudRateList[baudindex].BaudRate); return rate; } to CString ReadBaudDropdown(CComboBox *box) { int nBaudindex; CString strRate; strRate = ""; nBaudindex = box->GetCurSel(); if(nBaudindex > -1) strRate.Format("%s", BaudRateList[baudindex].BaudRate); return strRate; }

          1 Reply Last reply
          0
          • S ScarberryProd

            ok i have a header file and this is the error i get: error C2664: 'sprintf' : cannot convert parameter 1 from 'char' to 'char *' Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast and here is my code, im stumped: #define BAUDRATES_C #include "stdafx.h" #include "BaudRates.h" typedef struct{ char BaudRate[15]; unsigned char Length; }BaudRateType; const BaudRateType BaudRateList[16] = { {"110", 3}, {"200", 3}, {"300", 3}, {"1200", 4}, {"2400", 4}, {"4800", 4}, {"9600", 4}, {"14400", 5}, {"19200", 5}, {"28800", 5}, {"38400", 5}, {"56000", 5}, {"57600", 5}, {"115200", 6}, {"128000", 6}, {"256000", 6}, }; void PopulateBaudDropdown(CComboBox *box) { int i; for(i=0;i<16;i++) { box->AddString((char*)&BaudRateList[i].BaudRate); } } char ReadBaudDropdown(CComboBox *box) { int baudindex; char rate; baudindex = box->GetCurSel(); sprintf(rate,"%d",BaudRateList[baudindex].BaudRate); return rate; } please help, thank you --------------------- And Like The Wind Our Hero Vanishes Off Into The Distance...

            B Offline
            B Offline
            Brian D
            wrote on last edited by
            #5

            Why not just use char rate[256] // or whatever size you need BD


            "You know "that look" women get when they want sex? Me neither." --Steve Martin

            1 Reply Last reply
            0
            • S ScarberryProd

              ok i have a header file and this is the error i get: error C2664: 'sprintf' : cannot convert parameter 1 from 'char' to 'char *' Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast and here is my code, im stumped: #define BAUDRATES_C #include "stdafx.h" #include "BaudRates.h" typedef struct{ char BaudRate[15]; unsigned char Length; }BaudRateType; const BaudRateType BaudRateList[16] = { {"110", 3}, {"200", 3}, {"300", 3}, {"1200", 4}, {"2400", 4}, {"4800", 4}, {"9600", 4}, {"14400", 5}, {"19200", 5}, {"28800", 5}, {"38400", 5}, {"56000", 5}, {"57600", 5}, {"115200", 6}, {"128000", 6}, {"256000", 6}, }; void PopulateBaudDropdown(CComboBox *box) { int i; for(i=0;i<16;i++) { box->AddString((char*)&BaudRateList[i].BaudRate); } } char ReadBaudDropdown(CComboBox *box) { int baudindex; char rate; baudindex = box->GetCurSel(); sprintf(rate,"%d",BaudRateList[baudindex].BaudRate); return rate; } please help, thank you --------------------- And Like The Wind Our Hero Vanishes Off Into The Distance...

              B Offline
              B Offline
              Branislav
              wrote on last edited by
              #6

              error C2664: 'sprintf' : cannot convert parameter 1 from 'char' to 'char *' is right answer Why you would define char rate for only one character instead char rate[15]. You have defined char BaudRate[15] in BaudRateType structure: char& ReadBaudDropdown(CComboBox *box) { int baudindex; char rate[15]; rate[0] = 0; baudindex = box->GetCurSel(); if(baudindex != CB_ERR) sprintf(rate,"%s",BaudRateList[baudindex].BaudRate); return rate; } and calling: char *baud; baud = &ReadBaudDropdown(Cbox); if(baud[0] == 0) error?? // what you want to do ...

              1 Reply Last reply
              0
              • S ScarberryProd

                ok i have a header file and this is the error i get: error C2664: 'sprintf' : cannot convert parameter 1 from 'char' to 'char *' Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast and here is my code, im stumped: #define BAUDRATES_C #include "stdafx.h" #include "BaudRates.h" typedef struct{ char BaudRate[15]; unsigned char Length; }BaudRateType; const BaudRateType BaudRateList[16] = { {"110", 3}, {"200", 3}, {"300", 3}, {"1200", 4}, {"2400", 4}, {"4800", 4}, {"9600", 4}, {"14400", 5}, {"19200", 5}, {"28800", 5}, {"38400", 5}, {"56000", 5}, {"57600", 5}, {"115200", 6}, {"128000", 6}, {"256000", 6}, }; void PopulateBaudDropdown(CComboBox *box) { int i; for(i=0;i<16;i++) { box->AddString((char*)&BaudRateList[i].BaudRate); } } char ReadBaudDropdown(CComboBox *box) { int baudindex; char rate; baudindex = box->GetCurSel(); sprintf(rate,"%d",BaudRateList[baudindex].BaudRate); return rate; } please help, thank you --------------------- And Like The Wind Our Hero Vanishes Off Into The Distance...

                R Offline
                R Offline
                Renjith Ramachandran
                wrote on last edited by
                #7

                Hello for why should you try to get the value from the struct itself? You can Attach that value to the ComboBox by SetItemData() in that index you add the string and attach an itemdata then you can easily retrieve data corresponding to the selected item by using GetItemData() I want to change Myself..Can u help me? :)

                1 Reply Last reply
                0
                • S ScarberryProd

                  ok i have a header file and this is the error i get: error C2664: 'sprintf' : cannot convert parameter 1 from 'char' to 'char *' Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast and here is my code, im stumped: #define BAUDRATES_C #include "stdafx.h" #include "BaudRates.h" typedef struct{ char BaudRate[15]; unsigned char Length; }BaudRateType; const BaudRateType BaudRateList[16] = { {"110", 3}, {"200", 3}, {"300", 3}, {"1200", 4}, {"2400", 4}, {"4800", 4}, {"9600", 4}, {"14400", 5}, {"19200", 5}, {"28800", 5}, {"38400", 5}, {"56000", 5}, {"57600", 5}, {"115200", 6}, {"128000", 6}, {"256000", 6}, }; void PopulateBaudDropdown(CComboBox *box) { int i; for(i=0;i<16;i++) { box->AddString((char*)&BaudRateList[i].BaudRate); } } char ReadBaudDropdown(CComboBox *box) { int baudindex; char rate; baudindex = box->GetCurSel(); sprintf(rate,"%d",BaudRateList[baudindex].BaudRate); return rate; } please help, thank you --------------------- And Like The Wind Our Hero Vanishes Off Into The Distance...

                  R Offline
                  R Offline
                  Rahul200676
                  wrote on last edited by
                  #8

                  Hi, The variable rate is only one byte long, where as the first parameter type of sprint is char*, hence its giving u error. Try with rate as a char array. Rahul

                  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