Thanks for your help, everything you wrote pretty much fixed all the problems i was having with the program
On Mar 9, 8:45 pm, "Atamurad Hezretkuliyev" <[EMAIL PROTECTED]> wrote: > #include <stdio.h> > #include <stdlib.h> > > void insert_sort(int a[],int n); > > #define INDEX 10 > > int main() > { > int i; > int array[INDEX] = {6,4,2,5,1,2,8,3,7,9}; > > printf("Before the sort:\n"); > > for(i=0;i<INDEX;i++) > printf("%d", array[i]); > printf("\n"); > > insert_sort(array,INDEX); > printf("After the sort:\n"); > > for(i=0;i<INDEX;i++) > printf("%d \n", array[i]); > > return 0; > > } > > void insert_sort(int a[],int n) > { > int j, p; > int tmp; > > for(p = 1; p < n; p++) > { > tmp = a[p]; > for(j = p; j > 0 && a[j-1] > tmp; j--) > a[j] = a[j-1]; > a[j] = tmp; > } > > } > > 1. Put semicolon after function declaration. > void insert_sort(int a[],int n); > 2. You forgot do define INDEX at the beginning > #define INDEX 10 > 3. in C, you can not declare variables inside for loop > So "for(int i=0;i<INDEX;i++)" is wrong. > 4. Why don't you use gcc? > > [EMAIL PROTECTED]:~/cpp$ gcc inssort.c > [EMAIL PROTECTED]:~/cpp$ ./a.out > Before the sort: > 6425128379 > After the sort: > 1 > 2 > 2 > 3 > 4 > 5 > 6 > 7 > 8 > 9 > [EMAIL PROTECTED]:~/cpp$ > > atamyrat > > On 3/9/07, programming <[EMAIL PROTECTED]> wrote: > > > > > Hi fellow programmers, > > > I have some code that appears syntactically correct to me, however > > when i compile in on the Unversitites UNIX server, find that i get a > > couple of errors that really do not make sense to me. Hence, i thought > > i should post it on a forum and get somebodies expert opinion. Here is > > the code snipped: > > > --------------------------------------------------------------------------------------------------------------------------------------------------------------------- > > > #include <stdio.h> > > #include <stdlib.h> > > > void insert_sort(int a[],int n) > > > int main() > > { > > int i; > > int array[INDEX] = {6,4,2,5,1,2,8,3,7,9}; > > > printf("Before the sort:\n"); > > > for(int i=0;i<INDEX;i++) > > printf("%d", array[i]); > > printf("\n"); > > > insert_sort(array,INDEX); > > printf("After the sort:\n"); > > > for(int i=0;i<INDEX;i++) > > printf("%d \n", array[i]); > > > return 0; > > > } > > > void insert_sort(int a[],int n) > > { > > int j, p; > > int tmp; > > > for(p = 1; p < n; p++) > > { > > tmp = a[p]; > > for(j = p; j > 0 && a[j-1] > tmp; j--) > > a[j] = a[j-1]; > > a[j] = tmp; > > } > > } > > > -------------------------------------------------------------------------------------------------------------------------------------------------------------------- > > > Here is also a copy of the cryptic code message: > > > [EMAIL PROTECTED] Wk2]$ clearcc -ansi -Wall -o -Pendatic > > sorting_array.c > > sorting_array.c: In function `insert_sort': > > sorting_array.c:9: warning: 'main' is usually a function > > sorting_array.c:9: error: syntax error before '{' token > > sorting_array.c:11: error: `INDEX' undeclared (first use in this > > function) > > sorting_array.c:11: error: (Each undeclared identifier is reported > > only once > > sorting_array.c:11: error: for each function it appears in.) > > sorting_array.c:11: confused by earlier errors, bailing out > > -------------------------------------------------------------------------------------------------------------------------------------------------------------------- > > Thank you for anybody who is a help --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/algogeeks -~----------~----~----~----~------~----~------~--~---