[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

Re: segmentation fault



On Mon, Aug 21, 2000 at 08:23:41AM -0400, kamesh jayachandran wrote:
> Hai lip,
> I am getting segmentation fault while running the following quicksort program.
> My queries are
> 1)what is segmentation fault?
> 2)Will it always lead to dumping of core
> I hereby paste the program throwing segmentation fault
> //program starts here
> 
> #include<stdio.h>
> void quicksort(int [],int,int);
> int partition(int [],int,int);
>  main()
> {
> 	int i=10,x[10];
> 	printf("enter the numbers\n");
> 	for(i=0;i<10;i++)
> 		scanf("%d",&x[i]);
> 	quicksort(x,0,9);
> 	printf("elements of the array are\n");
> 	for(i=0;i<10;i++)
> 		printf("%d",x[i]);
> }
>  void quicksort(int x[],int lb,int ub)
> {
> 	int j;
> 	j=partition(x,lb,ub);
> 	quicksort(x,lb,j-1);
>     quicksort(x,j+1,ub);
> }
> int partition(int x[],int lb,int ub)
> {
> int t=x[lb];
> int down=lb,up=ub;
> int temp;
> if(lb>=ub)
> return 0;
> while(down<up)
> {
> while(t>=x[down])
> down++;
> while(t<=x[up])
> up--;
> if(down<up)
> {
> 	temp=x[down];
> 	x[down]=x[up];
> 	x[up]=temp;
> }
> }
> temp=x[up];
> x[up]=t;
> x[lb]=temp;
> return up;
> }
> //program ends here

I have a piece of advice for you, first learn C then try to write code.
Your prog in the above case will never work.

Kapil Bhalla