Thread: can't fix these errors

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    22

    can't fix these errors

    here are the errors and the code

    C:\matty\Microsoft Visual Studio\sorts.c(145) : error C2143: syntax error : missing ')' before ';'
    C:\matty\Microsoft Visual Studio\sorts.c(145) : error C2059: syntax error : ')'
    C:\matty\Microsoft Visual Studio\sorts.c(146) : error C2143: syntax error : missing ';' before 'if'
    ------------------------------------------------------------------------------------
    #include<stdio.h>
    #include<stdlib.h>
    #include<conio.h>

    #define num 5

    int array[num];
    int sarray[num];
    int swap;
    int compare;
    int iswap=0;
    int icompare=0;
    int shswap;
    int shcompare;
    int bswap;
    int bcompare;
    int current;
    void exch(int sarray[]);
    void ins_sort(int sarray[]);
    void shell_sort(int sarray[]);

    main()
    {
    int ctr=0,ctr1=0,ctr3=0;

    for(ctr1=0;ctr1<num;ctr1++)
    {
    array[ctr1]=(rand()%100);
    }
    for(ctr1=0;ctr1<num;ctr1++)
    {
    sarray[ctr3]=array[ctr1];
    ctr3++;
    }

    //print sorted array
    for(ctr3=0;ctr3<num;ctr3++)
    {
    printf("%d\t",sarray[ctr3]);
    }
    printf("Stats for Exchange sort");
    printf("%d\nNumber of swaps",swap);
    printf("%d\nNumber of comparisons",compare);
    printf("Stats for Insertion sort");
    printf("%d\nNumber of swaps",iswap);
    printf("%d\nNumber of comparisons",icompare);
    printf("Stats for Shell sort");
    printf("%d\nNumber of swaps",shswap);
    printf("%d\nNumber of comparisons",shcompare);
    printf("Stats for Bubble sort");
    printf("%d\nNumber of swaps",bswap);
    printf("%d\nNumber of comparisons",bcompare);
    return 0;
    }
    /******************************************/
    void exch(int sarray[])
    /******************************************/
    {
    int temp, //buffer var, same type as array elements
    other, current; // loop counters
    compare=0;
    swap=0;
    for (current = 0; current < num-1; current ++)
    {
    for (other = current+1; other < num; other ++)
    if (sarray[current] > sarray[other],compare++)
    //the current element is greater than the other element
    {
    //swap the 2 elements
    temp = sarray[current];
    sarray[current] = sarray[other];
    sarray[other] = temp;
    swap++;
    }
    }
    }
    /******************************************/
    void ins_sort(int sarray[])
    /*
    nb: number of elements in the array to be sorted
    ar[]: name of array to be sorted
    */
    /******************************************/
    {
    int temp, //buffer var of same type as array elements
    sub,next; //loop counters

    for (sub = 0; sub < num; sub++)
    {
    temp = sarray[sub];
    for (next = sub-1; temp < sarray[next] && next >= 0; next--)
    //search for insertion position
    {
    sarray[next+1] = sarray[next];
    }
    sarray[next+1] = temp;
    }
    }
    /******************************************/
    void shell_sort(int sarray[])
    /*
    nb: number of elements in the array to be sorted
    ar[]: name of array to be sorted
    */
    /******************************************/
    {
    int temp, //buffer var same type as elements of array
    ind, //loop counter
    other, // subscript of corresponding element in other partition
    interval, //size of interval
    finish; //boolean flag to indicate the sort is finished

    for (interval = num/2; interval >= 1; interval /= 2)
    {
    do
    {
    finish = 1; //sort is finished while there is no further swap
    for (ind = 0; ind < num-interval; ind++)
    {
    other = ind + interval;
    if (sarray[ind] > sarray[other],shcompare++)
    {
    temp = sarray[ind];
    sarray[ind] = sarray [other];
    sarray [other] = temp;
    shswap++;
    finish = 0;
    }
    }
    } while (!finish);
    }
    }
    /************************************************** ***/
    void bubbles(int sarray[])
    /************************************************** ***/
    {
    int temp, //buffer var, same type as array elements
    sub, current, // loop counters
    finish; // flag to signal the sort is finished
    // (to avoid unnecessary comparisons)

    for (sub = num, finish = 0; sub > 0 && !finish; sub--)
    {
    finish = 1; // sort is finished if we don't swap 2 elements
    for (current = 0; current < sub-1; current++;bcompare++)
    if (sarray[current] > sarray[current+1])
    //the current element is greater than the next element
    {
    //swap the 2 elements
    temp = sarray[current+1];
    sarray[current+1] = sarray[current];
    sarray[current] = temp;
    bswap++;
    finish = 0; //sort is not finished (2 elements have been swapped)
    }
    }
    }

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >for (current = 0; current < sub-1; current++;bcompare++)
    should be
    for (current = 0; current < sub-1; current++, bcompare++)

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  2. Strange/false errors
    By Ganoosh in forum Windows Programming
    Replies: 8
    Last Post: 10-20-2005, 04:54 PM
  3. strange errors?
    By egomaster69 in forum C Programming
    Replies: 6
    Last Post: 12-21-2004, 06:13 PM
  4. Help me with these errors... :-(
    By major_small in forum C++ Programming
    Replies: 6
    Last Post: 09-07-2003, 08:18 PM
  5. Errors when including winsock2.h
    By skiingwiz in forum Windows Programming
    Replies: 2
    Last Post: 12-27-2002, 07:32 PM