So uhm...I want to do the bubble sort and i found a code but actually i don't really know what's missing...ok...sorry but i am just a newbie and not so average of logic(lol. :p).
My goal here is to complete this code, 'cause i tried to run it but it has an error saying...

undefined symbol _main in module c0.ASM

and the code is :

Bubblesort (int data[],int n) {
   int tmp,i,j;

   for (i=0; i<n-1; i++) {
       for (j=0; j<n-i-1; j++)
            if (data[j] > data[j+1]) {
               tmp = data[j];
               data[j] = data[j+1];
               data[j+1] = tmp;
           }
   }
getch();
return 0;
}

my questions now are:
-where to put the printf("Enter values: ");?
-in the scanf, what variable i would use? is it the i or j or i would create new variable?
-and is there more code to add other than the printf(inputed value),scanf(inputed value)?
-of course i would display the sorted list but, where to put the printf(output) and what to put in the printf(output)?
-what does this mean (i=0; i<n-1; i++), (the red one)
---

i would really deeply appreciate if anyone can help me~ please~ *praying* TT_TT
also, sorry for asking so many questions.

Edited 6 Years Ago by addxztion: n/a

You have to add the main() function that includes all the code that does the things you stated in your questions.

Will I write it for you? NO. You will learn nothing if I do that.

Edited 6 Years Ago by Ancient Dragon: n/a

undefined symbol _main in module c0.ASM

A complete C program requires an entry point. The entry point is called main; you may have heard of it.

where to put the printf("Enter values: ");?

The main function that you're going to add.

in the scanf, what variable i would use? is it the i or j or i would create new variable?

I would write directly to the array (in main):

for (i = 0; i < n; i++)
{
    scanf("%d", a[i]);
}

and is there more code to add other than the printf(inputed value),scanf(inputed value)?

It depends on what you want the program to do. Perhaps you want to print the before and after to make sure the array is being sorted.

what does this mean (i=0; i<n-1; i++), (the red one)

Stop the loop before the last item in the array. It's the same as i < n except one step earlier.

You have to add the main() function that includes all the code that does the things you stated in your questions.

Will I write it for you? NO. You will learn nothing if I do that.

wah thanks ancient dragon. ^.^

A complete C program requires an entry point. The entry point is called main; you may have heard of it.

yeah i know. ^.^

The main function that you're going to add.

o..k.

I would write directly to the array (in main):
C Syntax (Toggle Plain Text)
for (i = 0; i < n; i++)
{
scanf("%d", a);
}

ok.

It depends on what you want the program to do. Perhaps you want to print the before and after to make sure the array is being sorted.

ok.

Stop the loop before the last item in the array. It's the same as i < n except one step earlier.

ok.
--
hehe~ thanks for helping me out. ^.^
though i understand quite a bit but i would figure this one out. *need to squeeze squeeze my twisted brain.* hehe~ :p

This question has already been answered. Start a new discussion instead.