English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

#include"stdio.h"
#include"conio.h"
void main()
{
void bubblesort(char *R[], int a); //function declaration//
char *restname[20][30]; //Variable in main//
bubblesort(restname[30], 20)//Function bubblesort in main//

void bubblesort(char *R[], int a)//function bubble sort//
{
int i, j;
char *hold;
for(i= 0; i < a; i++)
{
for(j=0; j {
if(R[j] < R[j+1])
{
hold = R[j];
R[j] = R[j+1];
R[j+1] = hold;}
}
}
for(i=0; i {
printf("%s", R[i]);
printf("\n");
}
} //end function//

}
}

help with the declaration part

2007-12-08 04:09:59 · 2 answers · asked by sriram 2 in Computers & Internet Programming & Design

2 answers

I see several potential problems...

(1) The function declaration for bubblesort goes above the main, not in it.

(2) The function itself appears within the main function. C doesn't allow nested functions.

(3) That function has as its first parameter an array of pointers to char. Fine, we sort arrays of pointers all the time. But then the sort algorithm sorts by the value of the pointer itself, not the value of the char indicated by that pointer. Sorting the pointers in this manner makes little sense.

2007-12-08 05:15:57 · answer #1 · answered by jgoulden 7 · 0 0

first any function declartion and definition should be out of main scope
not inside the main,the only thing inside the main is the fucntion call :)

secondly your array restname is empty ? why ? what are you sorting ?

good luck :)

#include"stdio.h"
#include"conio.h"


void bubblesort(char *R[], int a)//function bubble sort//
{
int i, j;
char *hold;
hold = new char;

for(i= 0; i < a; i++)
{
for(j=0; j {
if(R[j] < R[j+1])
{
hold = R[j];
R[j] = R[j+1];
R[j+1] = hold;}
}
}
for(i=0; i {
printf("%s", R[i]);
printf("\n");
}
} //end function//
void main()
{

char *restname[20][30]; //Variable in main//


bubblesort(restname[30], 20);//Function bubblesort in main//




}

2007-12-08 04:21:24 · answer #2 · answered by nado 2 · 0 0

fedest.com, questions and answers