void Recurse(TiXmlNode * pParentNode, CCObject * pParentObj) { std::string keyValue; for (TiXmlNode * pNode = pParentNode->FirstChild(); pNode; pNode = pNode->NextSiblingElement()) { TiXmlElement * pNodeNE = pNode->ToElement(); if (pNodeNE == NULL) continue; const char * szValue = pNodeNE->Value(); const char * szText = pNodeNE->GetText(); if (_stricmp(szValue, "key") == 0) { keyValue = szText; } else if (_stricmp(szValue, "dict") == 0) { CCDictionary * pNewDict = new CCDictionary; addObject(pParentObj, keyValue, pNewDict); Recurse(pNode, pNewDict); } else if (_stricmp(szValue, "array") == 0) { CCArray * pNewArray = new CCArray(); addObject(pParentObj, keyValue, pNewArray); Recurse(pNode, pNewArray); } else if (_stricmp(szValue, "string") == 0) { const char * szIn = szText == NULL ? "" : szText; std::wstring ret = ConvertToWString(szIn); CCString * pString = new CCString(ret.c_str()); addObject(pParentObj, keyValue, pString); } else if (_stricmp(szValue, "false") == 0 || _stricmp(szValue, "true") == 0) { CCBool * pBool = new CCBool(_stricmp(szValue, "true") == 0); addObject(pParentObj, keyValue, pBool); } else if (_stricmp(szValue, "integer") == 0) { CCInteger * pInt = new CCInteger(atoi(szText)); addObject(pParentObj, keyValue, pInt); } else if (_stricmp(szValue, "real") == 0) { CCReal * pReal = new CCReal(atof(szText)); addObject(pParentObj, keyValue, pReal); } else if (_stricmp(szValue, "date") == 0) { CCDate * pDate = new CCDate(getTimeFromString(szText)); addObject(pParentObj, keyValue, pDate); } else { assert(!"unknown value"); } } }
// -------------------------------------------------------------------------------- // prüft Benutzereingabe einer Uhrzeit über Input und schreibt bei Validität die // Daten via der Funktion getTimeFromString in ein TTime Konstrukt // -------------------------------------------------------------------------------- int getTime(char *Titel, TTime *Time) { *Input = '\0'; int Erg = 0; // Prüft, ob nach der Dauer des Termins gefragt wurde if(*Titel == 'D') { TTime *Z = calloc (1, sizeof(TTime)); // Speicher für die Eingabe reservieren CLEAR_LINE; printf("%s ", Titel); scanf("%10[^\n qwertzuiopü+*asdfghjklöä#'<>yxcvbnm,._;MNBVCXYÄÖLKJHGFDSAÜPOIUZTREWQ!""§$%&/()=?`'@€~]", Input); clearBuffer(); if(!getTimeFromString(Input, Z)) //rekursiver Aufruf, falls Eingabe nicht valide { UP(1); getTime(Titel, Time); } Time = Z; free(Z); } else { // Für alle Zeitaufrufe ausser der Dauer CLEAR_LINE; printf("%s ", Titel); scanf("%10[^\n qwertzuiopü+*asdfghjklöä#'<>yxcvbnm,._;MNBVCXYÄÖLKJHGFDSAÜPOIUZTREWQ!""§$%&/()=?`'@€~]", Input); clearBuffer(); if(!getTimeFromString(Input, Time)) //rekursiver Aufruf, falls Eingabe nicht valide { UP(1); getTime(Titel, Time); } } return Erg; }
int main() { TDate Date; TTime Time; char Input[20]; do { clearScreen(); printf("Geben Sie bitte ein gueltiges Datum ein (dd.mm.yyyy): "); *Input = '\0'; scanf("%19[^\n]", Input); clearBuffer(); if (*Input) if (getDateFromString(Input, &Date)) printf("Das Datum %02i.%02i.%04i ist gueltig!\n", Date.Day, Date.Month, Date.Year); else printf("Das eingegebene Datum %s ist ungueltig!\n", Input); else printf("Sie haben nichts eingegeben!\n"); printf("Geben Sie bitte eine gueltige Uhrzeit ein (st:mi:se): "); *Input = '\0'; scanf("%19[^\n]", Input); clearBuffer(); if (*Input) if (getTimeFromString(Input, &Time)) printf("Die Uhrzeit %02i:%02i:%02i ist gueltig!\n", Time.Hour, Time.Minute, Time.Second); else printf("Die eingegebene Uhrzeit ist ungueltig!\n"); else printf("Sie haben nichts eingegeben!\n"); } while (askAgain("Moechten Sie noch einmal (j//n) ? ")); return 0; }