Thread: Sorting chars in alphabetical order

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #7
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by Heisenberg800 View Post
    I solved the problem by changing the if statement to this
    Code:
    (strcmp(f[i].marke, f[j].marke) > 0 && f[j].marke[0] != '\0')
    The empty posts seemed to create the problem. So i made sure to not if statement if the post was empty.
    yeah if you're talking about the extra print outs even though it is not full, you might be able to use size of array then it will only go as far as the amount inside of it as well. that too should work. maybe not... let me try your way.

    yep
    you're smarter then me
    but you should still take a look at its return
    Code:
    /* Sort after car brand*/
    //int sortera(){ // does it really need a return value??? 
    // if yes then it is missing one. 
    void sortera(){
        // they are declared inside your for loops. 
     // int i,j; 
     
      fordon temp;
     
    for (int i = 0; i < 10; i++) 
      {
          for (int j = i+1; j < 10; j++)
          {
               // if (strcmp(f[i].marke, f[j].marke) > 0)
                if (strcmp(f[i].marke, f[j].marke) > 0 && f[j].marke[0] != '\0')
                {
                    temp = f[i]; 
                    f[i] = f[j]; 
                    f[j] = temp; 
                }
            }
        }
    }
    Last edited by userxbw; 11-25-2017 at 02:20 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sorting strings into alphabetical order
    By dude_tron_1982 in forum C Programming
    Replies: 5
    Last Post: 12-10-2010, 12:34 PM
  2. names in alphabetical order?
    By n3cr0_l0rd in forum C Programming
    Replies: 21
    Last Post: 02-06-2009, 08:59 PM
  3. Sorting in alphabetical order
    By fkheng in forum C Programming
    Replies: 3
    Last Post: 08-24-2003, 09:07 AM
  4. Sorting in Alphabetical order
    By Andre Santiago in forum C Programming
    Replies: 1
    Last Post: 12-13-2002, 06:14 PM
  5. Alphabetical order
    By BubbleMan in forum C++ Programming
    Replies: 1
    Last Post: 10-08-2001, 03:38 PM

Tags for this Thread