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. How to convert char* to char

How to convert char* to char

Scheduled Pinned Locked Moved C / C++ / MFC
databasehelptutorial
10 Posts 5 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.
  • V Offline
    V Offline
    vc _fragrance
    wrote on last edited by
    #1

    Hi, Can u plz say how to convert char* variable to char. I write the code as shown below struct row{ char name[50]; char sex[5]; }; I am getting text from the edit box and assigning to row.name, I want to insert row.name into the database. char *CampID=new char[50]; GetDlgItemText (IDC_EDITCAMPAIGNID,CampID,50); row.name=CampID; But I am getting error saying that "Can not convert from char* to char[50]" Thanks in advance.

    P _ 2 Replies Last reply
    0
    • V vc _fragrance

      Hi, Can u plz say how to convert char* variable to char. I write the code as shown below struct row{ char name[50]; char sex[5]; }; I am getting text from the edit box and assigning to row.name, I want to insert row.name into the database. char *CampID=new char[50]; GetDlgItemText (IDC_EDITCAMPAIGNID,CampID,50); row.name=CampID; But I am getting error saying that "Can not convert from char* to char[50]" Thanks in advance.

      P Offline
      P Offline
      prasad_som
      wrote on last edited by
      #2

      tejaswini.g wrote:

      char *CampID=new char[50]; GetDlgItemText (IDC_EDITCAMPAIGNID,CampID,50); row.name=CampID;

      you need to use strcpy here.

      strcpy(row.name,CampID);

      Prasad Notifier using ATL | Operator new[],delete[][^]

      V K 2 Replies Last reply
      0
      • P prasad_som

        tejaswini.g wrote:

        char *CampID=new char[50]; GetDlgItemText (IDC_EDITCAMPAIGNID,CampID,50); row.name=CampID;

        you need to use strcpy here.

        strcpy(row.name,CampID);

        Prasad Notifier using ATL | Operator new[],delete[][^]

        V Offline
        V Offline
        vc _fragrance
        wrote on last edited by
        #3

        Thank you. Shall I ask you One more doubt. I have created a propertysheet with two property pages. In the first property page i displayed 'employee names ' from the database and displayed in the grid lines. I select on name and activate another property page.Using querysiblings i got the name in the second property page. And using that ,employeename' i write a query to get the data from the database and displayed in the controls. First time it is running fine. Second time if i select another emplyoee name I am getting the correct results from database but the old data is displayed in the controls. Can u plz say How can I solve this problem? Thanks in advance.

        P 1 Reply Last reply
        0
        • V vc _fragrance

          Hi, Can u plz say how to convert char* variable to char. I write the code as shown below struct row{ char name[50]; char sex[5]; }; I am getting text from the edit box and assigning to row.name, I want to insert row.name into the database. char *CampID=new char[50]; GetDlgItemText (IDC_EDITCAMPAIGNID,CampID,50); row.name=CampID; But I am getting error saying that "Can not convert from char* to char[50]" Thanks in advance.

          _ Offline
          _ Offline
          _AnsHUMAN_
          wrote on last edited by
          #4

          tejaswini.g wrote:

          saying that "Can not convert from char* to char[50]"

          You can also go around with this using CString if you are using MFC Define the structure as: struct row{ CString name; CString sex; }; // In your code where you are retrieving the string you can write: char *CampID=new char[50]; GetDlgItemText (IDC_MYEDIT,CampID,50); row r; r.name =(CString )CampID; AfxMessageBox (r.name); // r.name has same string as CampID

          Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

          1 Reply Last reply
          0
          • V vc _fragrance

            Thank you. Shall I ask you One more doubt. I have created a propertysheet with two property pages. In the first property page i displayed 'employee names ' from the database and displayed in the grid lines. I select on name and activate another property page.Using querysiblings i got the name in the second property page. And using that ,employeename' i write a query to get the data from the database and displayed in the controls. First time it is running fine. Second time if i select another emplyoee name I am getting the correct results from database but the old data is displayed in the controls. Can u plz say How can I solve this problem? Thanks in advance.

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

            can you show some code?

            Prasad Notifier using ATL | Operator new[],delete[][^]

            V 1 Reply Last reply
            0
            • P prasad_som

              can you show some code?

              Prasad Notifier using ATL | Operator new[],delete[][^]

              V Offline
              V Offline
              vc _fragrance
              wrote on last edited by
              #6

              BOOL CCampaignDataEntryDlg::OnInitDialog() { CPropertyPage::OnInitDialog(); setUpODBC();// establish database connection long x=QuerySiblings(1,(long)&m_querySibling); CString* pString=(CString*)x; pStr=*pString; AfxMessageBox(pStr); //display employee name say 'tejaswini' SQLRETURN sr; SQLHSTMT hstmt; CString campid; campid.Format("SELECT empName,empID FROM EMPLOYEEDETAILS WHERE EMPNAME= '%s'",pStr); SQLCHAR* SQL = (SQLCHAR*)(LPCSTR)campid; } BOOL CCampaignDataEntryDlg::OnSetActive() { if(m_Status!="") //m_Status is to used to know whether the //property page is activated or not OnInitDialog(); return CPropertyPage::OnSetActive(); } BOOL CCampaignDataEntryDlg::OnKillActive() { m_Status="abc"; return CPropertyPage::OnKillActive(); }

              P D 2 Replies Last reply
              0
              • V vc _fragrance

                BOOL CCampaignDataEntryDlg::OnInitDialog() { CPropertyPage::OnInitDialog(); setUpODBC();// establish database connection long x=QuerySiblings(1,(long)&m_querySibling); CString* pString=(CString*)x; pStr=*pString; AfxMessageBox(pStr); //display employee name say 'tejaswini' SQLRETURN sr; SQLHSTMT hstmt; CString campid; campid.Format("SELECT empName,empID FROM EMPLOYEEDETAILS WHERE EMPNAME= '%s'",pStr); SQLCHAR* SQL = (SQLCHAR*)(LPCSTR)campid; } BOOL CCampaignDataEntryDlg::OnSetActive() { if(m_Status!="") //m_Status is to used to know whether the //property page is activated or not OnInitDialog(); return CPropertyPage::OnSetActive(); } BOOL CCampaignDataEntryDlg::OnKillActive() { m_Status="abc"; return CPropertyPage::OnKillActive(); }

                P Offline
                P Offline
                prasad_som
                wrote on last edited by
                #7

                tejaswini.g wrote:

                BOOL CCampaignDataEntryDlg::OnSetActive() { if(m_Status!="") //m_Status is to used to know whether the //property page is activated or not OnInitDialog(); return CPropertyPage::OnSetActive(); }

                dont call OnInitDialog here. Instead write that code in OnSetActive.

                Prasad Notifier using ATL | Operator new[],delete[][^]

                V 1 Reply Last reply
                0
                • P prasad_som

                  tejaswini.g wrote:

                  char *CampID=new char[50]; GetDlgItemText (IDC_EDITCAMPAIGNID,CampID,50); row.name=CampID;

                  you need to use strcpy here.

                  strcpy(row.name,CampID);

                  Prasad Notifier using ATL | Operator new[],delete[][^]

                  K Offline
                  K Offline
                  KarstenK
                  wrote on last edited by
                  #8

                  I would prefer strncpy(...) and set the last char to zero. :mad:

                  Greetings from Germany

                  1 Reply Last reply
                  0
                  • P prasad_som

                    tejaswini.g wrote:

                    BOOL CCampaignDataEntryDlg::OnSetActive() { if(m_Status!="") //m_Status is to used to know whether the //property page is activated or not OnInitDialog(); return CPropertyPage::OnSetActive(); }

                    dont call OnInitDialog here. Instead write that code in OnSetActive.

                    Prasad Notifier using ATL | Operator new[],delete[][^]

                    V Offline
                    V Offline
                    vc _fragrance
                    wrote on last edited by
                    #9

                    Thank you.

                    1 Reply Last reply
                    0
                    • V vc _fragrance

                      BOOL CCampaignDataEntryDlg::OnInitDialog() { CPropertyPage::OnInitDialog(); setUpODBC();// establish database connection long x=QuerySiblings(1,(long)&m_querySibling); CString* pString=(CString*)x; pStr=*pString; AfxMessageBox(pStr); //display employee name say 'tejaswini' SQLRETURN sr; SQLHSTMT hstmt; CString campid; campid.Format("SELECT empName,empID FROM EMPLOYEEDETAILS WHERE EMPNAME= '%s'",pStr); SQLCHAR* SQL = (SQLCHAR*)(LPCSTR)campid; } BOOL CCampaignDataEntryDlg::OnSetActive() { if(m_Status!="") //m_Status is to used to know whether the //property page is activated or not OnInitDialog(); return CPropertyPage::OnSetActive(); } BOOL CCampaignDataEntryDlg::OnKillActive() { m_Status="abc"; return CPropertyPage::OnKillActive(); }

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

                      tejaswini.g wrote:

                      long x=QuerySiblings(1,(long)&m_querySibling); CString* pString=(CString*)x; pStr=*pString;

                      QuerySiblings() does not return a value that can be cast to a CString. If page two wants to know the name that was selected on page one, store that name in the sheet (the common link between pages).


                      "Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.

                      "Judge not by the eye but by the heart." - Native American Proverb

                      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