Like Tree7Likes

Bubble sort algorithm help please, in C

This is a discussion on Bubble sort algorithm help please, in C within the C Programming forums, part of the General Programming Boards category; Originally Posted by BenBusby Forth line: int index; ? int index declares a variable called index but does not assign ...

  1. #16
    Registered User
    Join Date
    Nov 2012
    Posts
    1,067
    Quote Originally Posted by BenBusby View Post
    Forth line:
    int index; ?
    int index declares a variable called index but does not assign an initial value. The first part of a for loop is intended to assign the initial value. For example, to count from 1 to 10 we do this

    for (i=1; i <= 10; i++)
    printf("%d\n", i);

    Also, when you compile try to turn on warnings in your compiler and fix all of them. In your code you have some other things that should be caught by the compiler, for example:

    text= ("The two of");

    You made text an `int' variable and are trying to assign a string constant to it.

    text=text+" Clubs";

    Same here. You cannot add strings together in C in any meaningful way. For string concatenation there is `strcat'.

  2. #17
    Registered User
    Join Date
    Jan 2013
    Posts
    35
    It's done on an online compiler, I write on a page, then press a button 'Compile and run' I have no control over the settings.

    What suggestions do you have to get the text to work, is the something for me to google and research?

    Thank you sooo sooo much for you time

  3. #18
    Registered User
    Join Date
    Nov 2012
    Posts
    1,067
    There are freely downloadable compilers that don't have such restrictions. A popular one is GCC with Codeblocks. As I recall, it shows you all warnings by default.

    To concantate text look for the man page of strcat. For example search on "man 3 strcat" and you will find the answer. Or, you can find a way to accomplish what you're trying to do without string concatenation. For example

    printf("Hello, ");
    printf("world!");

    this will effectively concatenate the strings in your output. There's no need to store them.

  4. #19
    Registered User
    Join Date
    Jan 2013
    Posts
    35
    We need to use the compiler provided by the lecturer. I'm really perplexed at now i don't need to store them :s

  5. #20
    Registered User
    Join Date
    Nov 2012
    Posts
    1,067
    Quote Originally Posted by BenBusby View Post
    We need to use the compiler provided by the lecturer.
    No, you can use whatever compiler you want. As long as your end result compiles with the compiler provided by your lecuturer.

  6. #21
    Registered User
    Join Date
    Jan 2013
    Posts
    35
    "Each student must submit their coursework by writing to their assigned coursework page at the website" sorry it looks like it has to be done the way the lecturer wants :s

  7. #22
    Registered User
    Join Date
    Nov 2012
    Posts
    1,067
    Quote Originally Posted by BenBusby View Post
    "Each student must submit their coursework by writing to their assigned coursework page at the website"
    Does it say in the rules that students may submit their source code to web forums so that the people on the web forum can run it through their compilers and find the warnings for them?

    If you don't want to run the recommended checks yourself then that's your call, but there are good reasons to do it. Just because your prof didn't suggest it is not a good reason not to and it's clearly not forbidden by the rules to do so.

  8. #23
    Registered User
    Join Date
    Jan 2013
    Posts
    35
    Aha, no it doesn't. The online compiler will pick up mistakes like missing ';' or expected terms that aren't there, can it improve much on that?

    How can i solve the displaying the card description thing?

  9. #24
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,658
    Quote Originally Posted by BenBusby
    The online compiler will pick up mistakes like missing ';' or expected terms that aren't there, can it improve much on that?
    It can, by assuming some of the functionality of a static analysis tool rather than a mere compiler. This is what is typically done by a compiler that you might install yourself, with warnings turned on at a high level. Of course, such static analysis falls short of the scope of a dedicated tool, but then that is not the primary purpose of a compiler to begin with. So, use an offline compiler to help you.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. bubble sort algorithm - displaying content
    By scrfix in forum C Programming
    Replies: 7
    Last Post: 04-02-2012, 04:52 PM
  2. Bubble sort algorithm
    By Mr.Lnx in forum C Programming
    Replies: 37
    Last Post: 09-16-2011, 03:48 PM
  3. testing a bubble sort algorithm
    By rushhour in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2009, 12:00 AM
  4. Help, bubble-sort algorithm
    By webznz in forum C Programming
    Replies: 6
    Last Post: 10-30-2007, 01:28 AM
  5. help with debug (bubble sort algorithm)
    By lbraglia in forum C Programming
    Replies: 5
    Last Post: 10-19-2007, 05:24 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21