-
compiling problem
this program gives an error when i try to compile... i could not fix it. can anyone help me???
Code:
#include <stdio.h>
#include <conio.h>
#include <string.h>
typedef struct node {
int num;
struct node *test;
} new1;
new1 *sList;
void list_show (new1 *);
new1 list_sort(new1 *, new1 *);
int main ()
{
new1 nod4 = {18,NULL};
new1 nod3 = {15,&nod4};
new1 nod2 = {14,&nod3};
new1 nod1 = {10,&nod2};
sList=&nod1;
new1 tempnod = {12,NULL};
printf ("initial\n");
list_show(sList);
sList=list_sort(sList,&tempnod);
printf("Sorted List \n", tempnod.num);
list_show(sList);
getch();
return 0;
}
void list_show (new1 *list)
{
new1 *ptr=list, *j=NULL;
while (ptr!=NULL)
{
printf("%d", ptr->num);
ptr = ptr->test;
}
new1 list_sort(new1 *list, new1 *tempnod)
{
new1 *ptr=list, *j=NULL;
while (ptr!=NULL)
{
if ((ptr->num)<(tempnod->num))
{
j=ptr;
}
ptr = prt->test;
}
if (j!=NULL)
{
tempnod->test=j->test;
j->test=tempnod;
} else
{
tempnod->test=list;
list=tempnod;
}
return list;
}
-
Re: compiling problem
Is it asking too much to tell us the error and the line number? Really?
-
Re: compiling problem
Properly indenting your code will lead you to the problem.
-
Re: compiling problem
First of all, definiting a type called "new1" is just plain annoying.
In the below code 'sList' is a pointer but the method list_sort does not return a pointer.
Code:
new1 *sList;
new1 list_sort(new1 *, new1 *);
sList=list_sort(sList,&tempnod);
Another thing,
Code:
void list_show (new1 *list)
{
new1 *ptr=list, *j=NULL;
while (ptr!=NULL)
{
printf("%d", ptr->num);
ptr = ptr->test;
}
}
new1 list_sort(new1 *list, new1 *tempnod)
{
new1 *ptr=list, *j=NULL;
...
}
A third thing,
Code:
printf("Sorted List \n", tempnod.num);
You do not use the variable tempnod.num in the printf, remove it or use it.