Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

missing ';' before 'type' ? 1

Status
Not open for further replies.

ascikey

Programmer
Feb 18, 2004
127
GB
Hi all, I was messing with a quicksort but I cannot understand the error that I am getting

If the code is like the first it works fine but if it is like the second I get an error saying that there is a missing ; before type. the only diffeence in the two is the line "void quickSort(start1, end1);"
C:\Documents and Settings\asm\My Documents\QSORT.C(27) : error C2143: syntax error : missing ';' before 'type'

Code:
	int start1=0, end1=8, i=0, temp;
	void quickSort(start1, end1);
	for (i=0; i<=8; i++)
	{
		temp = arrayNumbers[i];
		printf("%d\n",temp);		
	}
	i = 0;	

	for (i=0; i<=8; i++)
	{
		temp = arrayNumbers[i];
		printf("%d\n",temp);		
	}
	return 0;
}


second with error
Code:
void main(void)
{
	int start1=0, end1=8, i=0, temp;
	
	for (i=0; i<=8; i++)
	{
		temp = arrayNumbers[i];
		printf("%d\n",temp);		
	}
	i = 0;

	void quickSort(start1, end1);

	for (i=0; i<=8; i++)
	{
		temp = arrayNumbers[i];
		printf("%d\n",temp);		
	}
	return 0;
Could anybody shed some light on this please
Thx Tony
 
When you call quickSort you shouldn't specify the return type. So, instead of "void quickSort(start1, end1);", just put "quickSort(start1, end1);"
 
thanks for your reply, i had tried that but i still got errors as shown, i have left the warnings in just in case they help. these are with the return type removed

C:\Documents and Settings\asm\My Documents\QSORT.C(26) : warning C4013: 'quickSort' undefined; assuming extern returning int
C:\Documents and Settings\asm\My Documents\QSORT.C(33) : warning C4098: 'main' : 'void' function returning a value
C:\Documents and Settings\asm\My Documents\QSORT.C(38) : error C2371: 'quickSort' : redefinition; different basic types
Erro
 
You declare main() to return void, yet you have return 0 at the end. Make main() return int instead. Also, make sure quickSort() is declared before main(). If that doesn't fix it, post the rest of your code as the problem doesn't seem to be in the code present.
 
thx for your quick reply again, the error is still there so here is the whole lot thx
Code:
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>

// Prototypes
void quicksort(int, int); // QuickSort function


// Globals
int arrayNumbers[9] = {20,3,28,12,1,29,11,14,25};

int main(void)
{
	int start1=0, end1=8, i=0, temp;
	
	for (i=0; i<=8; i++)
	{
		temp = arrayNumbers[i];
		printf("%d\n",temp);		
	}
	i = 0;
	quickSort(start1, end1);

	for (i=0; i<=8; i++)
	{
		temp = arrayNumbers[i];
		printf("%d\n",temp);		
	}
	return 0;
}


void quickSort(int start, int end)
	{
		if (end>start)
		{
		int pivotPosition=start, i=0, j=1;
		int pivot=arrayNumbers[start];
		printf("QuickSort called");
			for (i=start+1; i<=end; i++)
			{
				if (arrayNumbers[i]<pivot)
				{
					int temp=arrayNumbers[i];
					for (j=i; j>=pivotPosition+1; j--)
					{
						arrayNumbers[j]=arrayNumbers[j-1];
					}
					arrayNumbers[pivotPosition]=temp;
					pivotPosition++;
				}
			}
			quickSort(start,pivotPosition-1);
			quickSort(pivotPosition+1,end);

		}

	}
 
The fixes are highlighted in red ...

Code:
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>

// Prototypes
void [red]quickSort[/red](int, int); // QuickSort function
[green]//typo error ... C++ is case sensitive[/green]

// Globals
int arrayNumbers[9] = {20,3,28,12,1,29,11,14,25};

int main(void)
{
    int start1=0, end1=8, i=0, temp;
    
    for (i=0; i<=8; i++)
    {
        temp = arrayNumbers[i];
        printf("%d\n",temp);        
    }
    i = 0;
    quickSort(start1, end1);

    for (i=0; i<=8; i++)
    {
        temp = arrayNumbers[i];
        printf("%d\n",temp);        
    }
    return 0;
}


void quickSort(int start, int end)
    {
        if (end>start)
        {
        int pivotPosition=start, i=0, j=1;
        int pivot=arrayNumbers[start];
        printf("QuickSort called");
            for (i=start+1; i<=end; i++)
            {
                if (arrayNumbers[i]<pivot)
                {
                    int temp=arrayNumbers[i];
                    for (j=i; j>=pivotPosition+1; j--)
                    {
                        arrayNumbers[j]=arrayNumbers[j-1];
                    }
                    arrayNumbers[pivotPosition]=temp;
                    pivotPosition++;
                }
            }
            quickSort(start,pivotPosition-1);
            quickSort(pivotPosition+1,end);

        }

    }

Cheers ^^
 
Excellent thx very much, never even checked my spelling but next time i get weird results i will go through them first.
[yawn]
 
Btw, if you want to make your main() returning void type.

Code:
void main()
{
  [green]//the codes here ... blablabla[/green]
  
  return;[green]//This is optional
//you can exclude the return statement if you want.[/green]
}
 
ok done that thx. they both worked though is yours good programming practice ?
 
Yes. main() can return void type and you don't have to return a value if you don't need the return value. If you need some error checking to indicate normal and abnormal program termination, you can use exit().

Thus,

Code:
void main()
{
   [green]//Error checking here[/green]
   if([green]/*your error condition here*/[/green])
      exit(1); [green]//abnormal program termination[/green]

}
 
i see thank very much that will be very helpful
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top