#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    15
    Rep Power
    0

    Conversion Error


    When i try to run the followin code, it gaves me an error msg saying "error C2440: '=' : cannot convert from 'char *' to 'char [30]'
    There are no conversions to array types, although there are conversions to references or pointers to arrays"

    How can i solved this problem ?
    Code:
    
    	typedef struct nodex 
            {
    		 char first_name [30];
     		 char last_name[30];
             struct nodex   *nextPtr;
            } NODEX;
    
    void InsertInfo(LIST *pList)
    {
    CoInitialize(NULL);
    try 
            {
            _RecordsetPtr pRst("ADODB.Recordset");
            _bstr_t strCnn("DRIVER={Microsoft Access Driver (*.mdb)};UID=admin;DBQ=dbase.mdb");
    			pRst->Open("SELECT * FROM StudInfo", strCnn, adOpenStatic, adLockReadOnly, adCmdText);
            	 pRst->MoveFirst();
    
                	 while (!pRst->EndOfFile) {
    
    	NODEX *nodex;
    	nodex = (NODEX *) malloc (sizeof (NODEX));
    
    	nodex->last_name = (char*)((_bstr_t)pRst->GetFields()->GetItem("Lastname")->GetValue());
    	nodex->nextPtr = NULL;
    
    	if (pList->head == NULL)
    		pList->head = nodex;
    	else
    	{
    		nodex->nextPtr = pList->head;
    		pList->head = nodex;
    	}
    						        pRst->MoveNext();
                	 }
                	 pRst->Close(); 
                	 
            }
            catch (_com_error &e)
    
    
                {
                printf((char*) e.Description());
            }
            ::CoUninitialize();
    
    }
  2. #2
  3. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    nodex->last_name = (char*)((_bstr_t)pRst->GetFields()->GetItem("Lastname")->GetValue());

    try strcpy(nodex->last_name, (char*)((_bstr_t)pRst->GetFields()->GetItem("Lastname")->GetValue()));
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    15
    Rep Power
    0
    Thanks for you promt reply. But I am not trying to compare both the value. What I want is to assign the value of Last name from the database to the node in the link list. How can i archieve this ??
  6. #4
  7. Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    8
    Rep Power
    0
    It seems as though that is what his suggestion does. Give it a try and see if it works. Other than strcpy, the only way I know offhand to do what you are suggesting is to manually copy each character, incrementing the pointer, dereferencing, and assigning the array position to that value. But strcpy does all of this for you.

IMN logo majestic logo threadwatch logo seochat tools logo