Results 1 to 2 of 2

Thread: Bankfile dump code trouble

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    83

    Question Bankfile dump code trouble

    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:
    Code:
    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!)

    Code:
      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

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    1,262
    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:

    Code:
    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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

You may post new threads
You may post replies
You may post attachments
You may edit your posts
HTML code is Off
vB code is On
Smilies are On
[IMG] code is On