0 Replies - 1145 Views - Last Post: 12 November 2007 - 03:06 PM Rate Topic: -----

#1 Xardas  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 12-November 07

C - Need help using bubblesort to sort a 3d char array!

Posted 12 November 2007 - 03:06 PM

Hi, I am having some trouble with using a bubble sort alogrithm to sort a multidimensional array. I'm fairly new to all this and I cant see anything wrong with the code that I have written, but I'm not sure what the errors I'm getting mean. I'm using the Digital Mars Compiler with TextPad. This is the part of the code I'm having trouble with:
int sort_artist(int *count, char database[DATABASE][ARRAYSIZE][FIELDRANGE])
{
	int pass, counter;
	*count = 0;

	 for(pass = 0; pass < DATABASE - 1; pass++)
	 {
		for(counter = 0; counter < DATABASE - 1 - pass; counter++)
		{
			* count = * count + 1;

			if(strcmp(database[counter][0],database[counter+1][0]) > 0)
			{
				swap(&database[counter], &database[counter+1]); 
			}
		}
	}
}

int sort_title(int *count, char database[DATABASE][ARRAYSIZE][FIELDRANGE])
{
	int pass, counter;
	*count = 0;

	for(pass = 0; pass < DATABASE - 1; pass++)
	{
		for(counter = 0; counter < DATABASE - 1 - pass; counter++)
		{
			* count = * count + 1; //increments counter

			if(strcmp(database[counter][1],database[counter+1][1]) > 0)
			{
				swap(&database[counter], &database[counter+1]); 
			}
		}
 	}
}

int sort_genre(int *count, char database[DATABASE][ARRAYSIZE][FIELDRANGE])
{
	*count = 0;
	int pass,counter;

	for(pass = 0; pass < DATABASE - 1; pass++)
	{
		for(counter = 0; counter < DATABASE - 1 - pass; counter++) 
		{
			* count = * count + 1;

			if(strcmp(database[counter][2],database[counter+1][2]) > 0)
			{
				swap(&database[counter], &database[counter+1]); 
			}
		}
 	}
}

int swap(char *s1[ARRAYSIZE][FIELDRANGE], char *s2[ARRAYSIZE][FIELDRANGE])
{
	char temp[ARRAYSIZE][FIELDRANGE]; 

	temp = *s1;
	*s1 = *s2;
	*s2 = temp;
}




and these are the errors that I am getting:

{
^
C:\Users\DanAngelus\Documents\CMT 2060\MainApp\MainApp.c(169) : Error: 'swap' previously declared as something else
It was declared as: int C func(char (*)[*][*],char (*)[*][*])
It is now declared: int C func(char *(*)[*],char *(*)[*])
temp = *s1;
^
C:\Users\DanAngelus\Documents\CMT 2060\MainApp\MainApp.c(172) : Error: lvalue expected
temp = *s1;
^
C:\Users\DanAngelus\Documents\CMT 2060\MainApp\MainApp.c(172) : Warning 6: value of expression is not used
*s1 = *s2;
^
C:\Users\DanAngelus\Documents\CMT 2060\MainApp\MainApp.c(173) : Error: lvalue expected
*s1 = *s2;
^
C:\Users\DanAngelus\Documents\CMT 2060\MainApp\MainApp.c(173) : Warning 6: value of expression is not used
*s2 = temp;
^
C:\Users\DanAngelus\Documents\CMT 2060\MainApp\MainApp.c(174) : Error: lvalue expected
*s2 = temp;
^
C:\Users\DanAngelus\Documents\CMT 2060\MainApp\MainApp.c(174) : Warning 6: value of expression is not used
--- errorlevel 1

Tool completed with exit code 1



Any help would be great, so thanks in advance!

This post has been edited by Xardas: 12 November 2007 - 05:17 PM


Is This A Good Question/Topic? 0
  • +

Page 1 of 1