Can someone help with varible type problem
-
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...
-
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...
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
-
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
umm i changed it and still got the same error ty --------------------- And Like The Wind Our Hero Vanishes Off Into The Distance...
-
umm i changed it and still got the same error ty --------------------- And Like The Wind Our Hero Vanishes Off Into The Distance...
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; }
-
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...
-
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...
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 ...
-
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...
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? :)
-
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...
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