-
November 22nd, 2009, 05:02 PM
#1
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;
}
-
November 22nd, 2009, 07:16 PM
#2
Re: compiling problem
Is it asking too much to tell us the error and the line number? Really?
-
November 23rd, 2009, 03:26 AM
#3
Re: compiling problem
Properly indenting your code will lead you to the problem.
More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity. --W.A.Wulf
Premature optimization is the root of all evil --Donald E. Knuth
Please read Information on posting before posting, especially the info on using [code] tags.
-
November 23rd, 2009, 09:05 AM
#4
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.
Last edited by laasunde; November 23rd, 2009 at 09:09 AM.
Before post, make an effort yourself, try googling or search here.
When posting, give a proper description of your problem, include code* and error messages.
*All code should include code tags
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|