예제 #1
0
파일: graph.c 프로젝트: aaa1616/Fairy
BINTREE *createBinTreeLR()
{
	char lstr[20];
	char rstr[20];

	FILE *file = fopen("input.txt", "r");
	myscanf(file, "%s%s", lstr, rstr);

	int n = strlen(lstr);
	BINTREENODE *root = subCreate(lstr, rstr, n);

	BINTREE *bt;
	bt = malloc(sizeof(BINTREE));
	memset(bt, 0, sizeof(BINTREE));
	bt->root = root;

	return bt;
}
예제 #2
0
파일: main.cpp 프로젝트: congpp/VS_Proj
void AddNewX() {
    // Define ADO object pointers. Initialize pointers on define.  
    _RecordsetPtr pRstEmployees = NULL;
    _ConnectionPtr pConnection = NULL;

    // Define Other variables  
    IADORecordBinding *picRs = NULL;   // Interface Pointer declared.(VC++ Extensions)     
    CEmployeeRs emprs;   // C++ class object     

    HRESULT hr = S_OK;

    // Replace Data Source value with your server name.  
    _bstr_t strCnn("Provider='sqloledb'; Data Source='My_Data_Source'; Initial Catalog='pubs'; Integrated Security='SSPI';");
    _bstr_t strId;
    _bstr_t strMessage;

    try {
        // Open a connection  
        TESTHR(pConnection.CreateInstance(__uuidof(Connection)));
        pConnection->Open(strCnn, "", "", adConnectUnspecified);

        // Open employee table   
        TESTHR(pRstEmployees.CreateInstance(__uuidof(Recordset)));

        // You have to explicitly pass the Cursor type and LockType to the Recordset here  
        pRstEmployees->Open("employee", _variant_t((IDispatch *)pConnection, true),
            adOpenKeyset, adLockOptimistic, adCmdTable);

        // Open IADORecordBinding interface pointer for Binding Recordset to a class      
        TESTHR(pRstEmployees->QueryInterface(__uuidof(IADORecordBinding), (LPVOID*)&picRs));

        // Bind the Recordset to a C++ Class here     
        TESTHR(picRs->BindToRecordset(&emprs));

        // Get data from the user.The employee id must be formatted as first,middle and last   
        // initial, five numbers,then M or F to signify the gender. For example, the   
        // employee id for Bill A. Sorensen would be "BAS55555M".   
        printf("Enter Employee Id: ");
        myscanf(emprs.m_sz_empid, sizeof(emprs.m_sz_empid));
        strId = emprs.m_sz_empid;
        printf("Enter First Name: ");
        myscanf(emprs.m_sz_fname, sizeof(emprs.m_sz_fname));
        printf("Enter Last Name:");
        myscanf(emprs.m_sz_lname, sizeof(emprs.m_sz_lname));

        // Proceed if user entered id, the first and the last name.   

        if (strcmp(emprs.m_sz_empid, "") && strcmp(emprs.m_sz_fname, "") && strcmp(emprs.m_sz_lname, "")) {
            // This adds a new record to the table     
            // if (FAILED(hr = picRs->AddNew(&emprs)))  
            //_com_issue_error(hr);  
            TESTHR(picRs->AddNew(&emprs));

            // Show the newly added data  
            printf("New Record: %s  %s  %s \n", \
                emprs.lemp_empidStatus == adFldOK ? emprs.m_sz_empid : "<NULL>", \
                emprs.lemp_fnameStatus == adFldOK ? emprs.m_sz_fname : "<NULL>", \
                emprs.lemp_lnameStatus == adFldOK ? emprs.m_sz_lname : "<NULL>");
        }
        else
            printf("Please enter an employee id, first name and last name.\n");

        // Delete the new record because this is a demonstration.   
        pConnection->Execute("DELETE FROM EMPLOYEE WHERE emp_id = '" + strId + "'", NULL, adCmdText);
    }
    catch (_com_error &e) {
        // Notify the user of errors if any.  
        _variant_t vtConnect = pRstEmployees->GetActiveConnection();

        // GetActiveConnection returns connect string if connection  
        // is not open, else returns Connection object.  
        switch (vtConnect.vt) {
        case VT_BSTR:
            printf("Error:\n");
            printf("Code = %08lx\n", e.Error());
            printf("Message = %s\n", e.ErrorMessage());
            printf("Source = %s\n", (LPCSTR)e.Source());
            printf("Description = %s\n", (LPCSTR)e.Description());
            break;
        case VT_DISPATCH:
            PrintProviderError(vtConnect);
            break;
        default:
            printf("Errors occured.");
            break;
        }
    }

    // Clean up objects before exit.  Release the IADORecordset Interface here     
    if (picRs)
        picRs->Release();

    if (pRstEmployees)
        if (pRstEmployees->State == adStateOpen)
            pRstEmployees->Close();
    if (pConnection)
        if (pConnection->State == adStateOpen)
            pConnection->Close();
}