PDA

View Full Version : Bankfile dump code trouble



reaver
06-26-2002, 09:41 AM
Was bored at work, so started looking thru the new code that was added to dump Bank/Equip information to a file.

My goal: to clean up the output of the file by removing the Lore information if its the same as the item name.

Problem: Last time I programmed was in Fortran77 :P So, C++ and QT are totally unfamiliar.


Here's the current snipet of code from interface.cpp as of the latest CVS:


QFile bankfile(Qstring("/tmp/bankfile.") + Qstring::number(getpid()));
if (bankfile.open(IO_Append | IO_WriteOnly))
{
QTextStream out(&bankfile);
out << "Item: " << itemp->item.name;
if (itemp->item.stackable == 1)
out << "x" << itemp->item.number;
out << ",(" << itemp->item.lore << "), Slot: " // This is what I want to change
<< slotName << endl;
}



What I want to change is to only output Lore info if item.name does not equal item.lore AND item.name does not equal "*" + item.lore. So here is my miserable attempt at coding in a language I don't understand yet (flame on!)



if ((item.name != itemp->item.lore) &&
(item.name != "*" + itemp->item.lore))
out << ",(" << itemp->item.lore << ")";
out << ", Slot: " << slotName << endl;


Any tips, /rudes, cackles or rtfm comments welcome ;)

-Reaver

high_jeeves
06-26-2002, 10:01 AM
Strings in C/C++ are really char* (pointers to an array of characters). So, by doing a ==, != compare of them, you are checking to see if the POINTERS are the same.

Take a look at the function "strcmp" (do a man strcmp to get details). It will compare two strings, and return you a result.

So, perhaps more like:



if (strcmp(itemp->item.name, itemp->item.lore) != 0 &&
strcmp(itemp->item.name, (char *)(itemp->item.lore + 1)) != 0)
{
out << ",(" << itemp->item.lore << ")";
}


This will compare the name and the lore, then the name and the (lore + 1), which is the lore name starting at character 1 (to avoid a potential "*"). If both of these strings dont match, then output the lore name.

--Jeeves