Thread: Sorting string array

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    66
    uniquecount = 0; worked.

    It still seems that the [x+1] would be accessing an array location that does not exist. But if it works, it doesn't matter, I guess, since it wouldn't cause wrong output.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Furious5k View Post
    uniquecount = 0; worked.

    It still seems that the [x+1] would be accessing an array location that does not exist. But if it works, it doesn't matter, I guess, since it wouldn't cause wrong output.
    Well, instead of looking at the next element, perhaps you should stuff the first element into the Unique array, and then compare with the latest element in the Unique array to see if you need to add it or not.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Dec 2008
    Posts
    66
    Code:
    for (int q = 0; q < uniquecount; ++q)
              {
                for (int w = 0; w < BOOK_MAX; ++w)
                  {
                    if (Unique[q] == Books[w].Author)
                      {
                        cout << Books[w].Title << " in section " << Books[w].Category;
    
                        for (int e = 0; e < BOOK_MAX; ++e)
                          {
                            if (Book[w].ID == Loans[e].Book)
                              {
                                cout << " - on Loan." << endl;
                              }
                            else
                              {
                                cout << " - in Stock." << endl;
                              }
                          }
                      }
                  }
              }
    198: parse error before `['
    213: break statement not within loop or switch
    214: confused by earlier errors, bailing out

    Line 198 is the if statement.
    I'm confused about break statement, because the switch statement it's in is within braces.
    The switch starts and ends as follows:
    Code:
    switch (select)
         {
         case 1:
           {
    Code:
            break;
           }
         case 2:
    I didn't have any errors before writing the code that starts at the point which I've pasted.
    Last edited by Furious5k; 01-06-2009 at 10:32 AM.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You probably have an error elsewhere - what you have posted seems OK to me.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting 2D string array
    By sureshhewa in forum C Programming
    Replies: 14
    Last Post: 07-27-2008, 01:30 PM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. can't assign proper values to an array of string
    By Duo in forum C Programming
    Replies: 1
    Last Post: 04-04-2005, 06:30 AM
  4. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM
  5. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 11:06 PM