void printReferences() const { char* buffer = (char*) malloc(1); buffer[0] = '\0'; { pthread_mutex_lock(&mLock); char tmpBuffer[128]; sprintf(tmpBuffer, "Strong references on Object %p (WeakReference %p):\n", mObject, this); buffer = (char*) realloc(buffer, strlen(buffer) + strlen(tmpBuffer) + 1); strcat(buffer, tmpBuffer); buffer = printItems(buffer, mStrongReferences); sprintf(tmpBuffer, "Weak references on Object %p (WeakReference %p):\n", mObject, this); buffer = (char*) realloc(buffer, strlen(buffer) + strlen(tmpBuffer) + 1); strcat(buffer, tmpBuffer); buffer = printItems(buffer, mWeakReferences); pthread_mutex_unlock(&mLock); } DEBUG_INFO("%s", buffer); free(buffer); }
void MenuConf::printItems(Item* item, int indent) { while(item) { for(int i=0; i<indent; i++) _putch(' '); if(item->data) { if(item->data->name[0]) { printf("%s: ", item->data->name); } printf("'%s'", item->data->caption); if(item->data->hotkeys) { printf(", ["); for(Hotkey* h=item->data->hotkeys; h; h=h->nextSibling) { printf(h->string); if(h->nextSibling) printf(", "); } printf("]"); } printf("\n"); } else { printf("---\n"); } printItems(item->firstChild, indent+2); item = item->nextSibling; } }
int main() { Item i_array[SIZE]; int itemSize = 0; int choice; bool repeat = 1; // Welcome message cout << "WELCOME TO OBSCURA ANTIQUES & ODDITIES!\n\n"; // Begin loop do { choice = menu(); switch (choice) { case 1: add(itemSize, i_array); break; case 2: printPopular(i_array); break; case 3: printItems(itemSize, i_array); break; case 4: saveInventory(); cout << "Goodbye!"; repeat = 0; } } while (repeat); return 0; }
void UseItemCommand::execute(Game & game) { string input = { "" }; while (true) { vector<Item*> list = getUseableItemsInInventory(game.getHero()); printItems(list); input = IOHelper::read(); if (IOHelper::isInputGameReady(input, game)) { int i{ IOHelper::parseToInt(input) }; if (i > 0 && i <= list.size()) { int k{ 0 }; for (Item* e : list) { k++; if (i == k) { SpecialItem* item = dynamic_cast<SpecialItem*>(e); if (item) { if (item->use(game.getHero().getLocation(), game.getXSize(), game.getYSize(), game.getZSize())) { game.getHero().removeItem(*item); } } else { Potion* potion = dynamic_cast<Potion*>(e); if (potion) { potion->consume(game.getHero()); game.getHero().removeItem(*potion); } else { // Should not happen IOHelper::writeLine("You cannot use this item... :("); } } return; } } } else if (i == list.size() + 1) { // Cancel operation called return; } else { IOHelper::writeInvalidCommand(); } } } }
int main(int argc, char *argv[]) { FILE *file = initFile(); init(file); if(argc == 1){ printItems(); } else { if(!strcmp(argv[1],"add")){ if(argc<3){ printf("Usage: todo add [<priority>] <text>\n"); } else { insertItem(argv,argc); } } if(!strcmp(argv[1],"del")){ if(argc<3){ printf("Usage: todo del <id>\n"); } else { deleteItem(atoi(argv[2])); } } if(!strcmp(argv[1],"swap")){ if(argc<4){ printf("Usage: todo swap <id1> <id2>\n"); } else { swapIDs(atoi(argv[2]), atoi(argv[3])); } } /* if(!strcmp(argv[1],"prio")){ if(argc < 4){ printf("Usage: todo prio <id> <new_prio>\n"); } else { changePrio(atoi(argv[2]), atoi(argv[3])); } } */ } cleanUp(); return 0; }
/*################################################################*/ int main() { item itemArray[3]; int num_item = 3; /* Number of item. */ getItems(itemArray,num_item); printItems(itemArray,num_item); return 0; }
// Function: printItemsAndTotal // Inputs: NA // Outputs: NA // Description: Print the items and subtotal, tax, and total. // void ContractorSale::printItemsAndTotal() { printItems(); std::cout << BAR << TAB << SUBTOTAL << getSubTotal() << std::endl; std::cout << BAR << TAB << SALE_CONT << std::endl; std::cout << BAR << TAB << CONT_ID << contractorID << std::endl; std::cout << BAR << TAB << DISCOUNT << OPEN_PERC << discount*100 << CLOSE_PERC << amtDiscounted << std::endl; std::cout << BAR << TAB << SUBTOTAL << getSubTotal() << std::endl; std::cout << BAR << TAB << TAX << OPEN_PERC << getTaxRate()*100 << CLOSE_PERC << getTotalTax() << std::endl; std::cout << BAR << TAB << TOTAL_AMT << getTotalAmt() << std::endl; }
Item *generateItems(int n) { srand(time(NULL)); Item *arr=(Item*)calloc(n,sizeof(Item)); int i=0; while(i<n){ arr[i].v=(double)(rand()%MAX_V)*(rand()%10)/10+1; arr[i].w=(unsigned int)(rand()%MAX_W); i++; } printItems(arr,n); return arr; }
/** Initializes the view of this widget. */ void CSearchResultView::initView() { setToolTip(tr("Search result of the selected work")); setHeaderLabel(tr("Results")); setDragEnabled(true); setRootIsDecorated( false ); setSelectionMode(QAbstractItemView::ExtendedSelection); //setup the popup menu m_popup = new QMenu(this); m_actions.copyMenu = new QMenu(tr("Copy..."), m_popup); m_actions.copyMenu->setIcon(CResMgr::searchdialog::result::foundItems::copyMenu::icon()); m_actions.copy.result = new QAction(tr("Reference only"), this); BT_CONNECT(m_actions.copy.result, SIGNAL(triggered()), this, SLOT(copyItems())); m_actions.copyMenu->addAction(m_actions.copy.result); m_actions.copy.resultWithText = new QAction(tr("Reference with text"), this); BT_CONNECT(m_actions.copy.resultWithText, SIGNAL(triggered()), this, SLOT(copyItemsWithText())); m_actions.copyMenu->addAction(m_actions.copy.resultWithText); m_popup->addMenu(m_actions.copyMenu); m_actions.saveMenu = new QMenu(tr("Save..."), m_popup); m_actions.saveMenu->setIcon(CResMgr::searchdialog::result::foundItems::saveMenu::icon()); m_actions.save.result = new QAction(tr("Reference only"), this); BT_CONNECT(m_actions.save.result, SIGNAL(triggered()), this, SLOT(saveItems()) ); m_actions.saveMenu->addAction(m_actions.save.result); m_actions.save.resultWithText = new QAction(tr("Reference with text"), this); m_actions.saveMenu->addAction(m_actions.save.resultWithText); BT_CONNECT(m_actions.save.resultWithText, SIGNAL(triggered()), this, SLOT(saveItemsWithText())); m_popup->addMenu(m_actions.saveMenu); m_actions.printMenu = new QMenu(tr("Print..."), m_popup); m_actions.printMenu->setIcon(CResMgr::searchdialog::result::foundItems::printMenu::icon()); m_actions.print.result = new QAction(tr("Reference with text"), this); BT_CONNECT(m_actions.print.result, SIGNAL(triggered()), this, SLOT(printItems())); m_actions.printMenu->addAction(m_actions.print.result); m_popup->addMenu(m_actions.printMenu); }
double getFractionalSoln(Item* arr , int n , int W) { qsort(arr,n,sizeof(Item),compItem); printf("After sorting , ");printItems(arr,n); double val=0; int w=0 ,i=0; do{ val+=arr[i].v; w +=arr[i].w; i++; printf("w=%f\n",w); }while(w<W && i<n); if(w<W){ printf("Fractional Solution is %f.\n",w); return w; } i--; val-=arr[i].v; w -=arr[i].w; val+=(W-w)*(arr[i].v)/(arr[i].w); printf("Fractional Solution is %f\n",val); return val; }
MenuConf::MenuConf(const char* filename) : filename(filename) , lineIndex(0) , indentChar(0) , parentIndent(0) , firstItem(0) , curParent(0) , caret(0) { printf("MenuConf (%s)\n", filename); FILE* f = fopen(filename, "rt"); if(! f) { printf("MenuConf: failed open %s", filename); return; } nextChar(f); while(true) { caret = 0; lineIndex ++; if(curChar == EOF) break; int indent = 0; while(curChar == ' ' || curChar == '\t') { if(indentChar == 0) indentChar = curChar; if(indentChar != curChar) { printf("Mixed tabs and whitespace in %s.\nUse either tabs or whitespace for indentation.\n", filename); return; } indent ++; nextChar(f); } if(curChar == EOF) { //printf("%d: EOF\n", lineIndex); break; } else if(curChar == '\n') { //printf("%d: blank\n", lineIndex); nextChar(f); } else if(isAlpha(curChar) || curChar=='"') { //printf("%d: item\n", lineIndex); //eatLine(f); Item* item = new Item(new ItemData()); item->indent = indent; if(readItemNameIfPresent(f, item)) { if(readItemCaption(f, item)) { readItemHotkeysIfPresent(f, item); } } eatLine(f); while(curParent && item->indent <= curParent->indent) { curParent = curParent->parent; } addChild(curParent, item); curParent = item; } else if(curChar == '-' && nextChar(f) == '-' && nextChar(f) == '-') { //separator Item* item = new Item(NULL); item->indent = indent; while(curParent && item->indent <= curParent->indent) curParent = curParent->parent; addChild(curParent, item); curParent = item; eatLine(f); } else { //comment eatLine(f); } } fclose(f); printItems(firstItem, 0); }
void ParamSet::Print(int indent) const { printItems("integer", indent, ints); printItems("boolean", indent, bools); printItems("float", indent, floats); printItems("point2", indent, point2fs); printItems("vector2", indent, vector2fs); printItems("point", indent, point3fs); printItems("vector", indent, vector3fs); printItems("normal", indent, normals); printItems("string", indent, strings); printItems("texture", indent, textures); printItems("rgb", indent, spectra); }