Thread: problem with bubble sort

  1. #1
    Registered User
    Join Date
    Aug 2012
    Posts
    11

    problem with bubble sort

    Code:
    void 
    sort(int values[], int n)
    {
        int swapped = 1;
        while (swapped == 1)
            swapped = 0;
            for (i = 0; i < (n - 1); i++)
                if (values[i] > values[i + 1])
                {
                    int temp = values[i];
                    values[i] = values[i+1];
                    values[i+1] = temp;
                    swapped = 1;
                }
        else
            return 0;         
    }
    I'm running Fedora and compiling with gcc. I don't know why but it is not compiling. I get this error: jharvard@appliance (~/pset3): make helpers make: *** No rule to make target `helpers'. Stop.
    Last edited by Dave Couture; 08-20-2012 at 02:06 PM.

  2. #2
    Registered User
    Join Date
    Apr 2008
    Posts
    396
    Hmm... this error has nothing to do with the compiler or your code, it's a problem with the makefile.
    The rule "helpers" apparently doesn't exist or maybe the name of the makefile is not standard and you have to specify it on the command line.

  3. #3
    Registered User
    Join Date
    Aug 2012
    Posts
    11
    here is the makefile
    Code:
    #
    # Makefile
    #
    # Computer Science 50
    # Problem Set 3
    #
    
    all: find generate
    
    find: find.c helpers.c helpers.h
        gcc -ggdb -std=c99 -Wall -Werror -o find find.c helpers.c -lcs50 -lm
    
    generate: generate.c
        gcc -ggdb -std=c99 -Wall -Werror -o generate generate.c
    
    clean:
        rm -f *.o a.out core find generate

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Even once that compiles, there is a very obvious bug in that your while loop only embodies line 6, and not lines 7 - 14.
    You also can't return 0 from a void returning function, not that you want a return statement in this function at all anyway.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  5. #5
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Quote Originally Posted by Dave Couture View Post
    here is the makefile
    Code:
    #
    # Makefile
    #
    # Computer Science 50
    # Problem Set 3
    #
    
    all: find generate
    
    find: find.c helpers.c helpers.h
        gcc -ggdb -std=c99 -Wall -Werror -o find find.c helpers.c -lcs50 -lm
    
    generate: generate.c
        gcc -ggdb -std=c99 -Wall -Werror -o generate generate.c
    
    clean:
        rm -f *.o a.out core find generate
    Yep, root4 called it: you don't have a 'helpers' target in your make file. You have targets 'all', 'find', 'generate' and 'clean'. If you want to use the command 'make helpers', you must write a 'helpers' target. Follow the pattern used for find and generate. You should also try reading a tutorial or two on using make and on writing make files. Check the tutorials on our site.
    Last edited by anduril462; 08-20-2012 at 04:07 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem with gets and bubble sort
    By wwwildbill in forum C Programming
    Replies: 4
    Last Post: 04-04-2009, 01:31 AM
  2. Bubble sort problem
    By wwwildbill in forum C Programming
    Replies: 2
    Last Post: 03-27-2009, 04:43 PM
  3. Problem w/ Bubble Sort
    By ktpchipper in forum C Programming
    Replies: 3
    Last Post: 12-04-2004, 02:59 PM
  4. Bubble Sort / selection problem
    By Drew in forum C++ Programming
    Replies: 7
    Last Post: 08-26-2003, 03:23 PM