Please Help Linked list problems!

R

RBCC

Please Help!

I am using this structure :

typedef struct Sname
{
char *pSzfirst;
char *pSzLast;
struct name *Snext;
}

person* FindMin (person *pSHead)
{
person *pSMin;
person *pSCurr;

pSMin=pSHead;
pSCurr=pSHead;

while (pScurr!= NULL)
{
if (strcmp(pScurr->pszfirst,pSMin->pszfirst)<0)
{
pSMin=pSCurr;

}

pSCurr=pScurr->Snext;
}

return psMin;
} //Error:Expected a declaration! What can I do to make this work?

Could somebody please write a piece of code that will walk the list?
Thank you, John
 
O

osmium

RBCC said:
Please Help!

I am using this structure :

typedef struct Sname
{
char *pSzfirst;
char *pSzLast;
struct name *Snext;
}

person* FindMin (person *pSHead)
{
person *pSMin;
person *pSCurr;

pSMin=pSHead;
pSCurr=pSHead;

while (pScurr!= NULL)
{
if (strcmp(pScurr->pszfirst,pSMin->pszfirst)<0)
{
pSMin=pSCurr;

}

pSCurr=pScurr->Snext;
}

return psMin;
} //Error:Expected a declaration! What can I do to make this work?

Could somebody please write a piece of code that will walk the list?

When all else fails, try being honest. You are trying to con us in to
believing you have a linked list which needs a "few final touches". Provide
a *program* (not an extract) that shows some promise as to becoming a linked
list. Then you will likely get some help in walking the list.

I suggest you write a print function to aid in debugging, you may well
discard it when the thing is working. There is no sin in writing code that
is only used for debugging.
 
C

Cristian-Matei Toader

I am using this structure :

typedef struct Sname
{
  char *pSzfirst;
  char *pSzLast;
 struct name *Snext;

} ....
} //Error:Expected a declaration!  What can I do to make this work?

You have a typing error, it should be "struct Sname *Snext;" instead
of "struct name *Snext;". Therefore when you type struct name the
compiler is expecting to declare the new structure type.
 
E

Eric Sosman

Please Help!

I am using this structure :

typedef struct Sname
{
char *pSzfirst;
char *pSzLast;
struct name *Snext;

This is perfectly all right, but almost certainly not what
you intended. I strongly suspect that you mean `struct Sname'
here, or else that you meant `struct name' above. I also strongly
suspect that the code you have shown us is not the code that's
giving you trouble; it follows that our diagnoses and suggestions
may be wide of the (hidden) mark, and if so, that you have no one
but yourself to blame for our inaccuracies.

Where is the identifier the `typedef' declares? And where is
the semicolon that concludes the declaration? I'm going to proceed
on the assumption that `person;' comes after the `}', and if my
assumption is wrong -- well, again, it's your fault.
person* FindMin (person *pSHead)
{
person *pSMin;
person *pSCurr;

pSMin=pSHead;
pSCurr=pSHead;

while (pScurr!= NULL)
{
if (strcmp(pScurr->pszfirst,pSMin->pszfirst)<0)

This shakes my faith in my assumption that `struct Sname' and
`person' are the same thing. The problem is that `struct Sname' has
no element named `pszfirst', so the compiler would have complained.
But perhaps `person' is something entirely different, something that
*does* have a `pszfirst' element? Perhaps. But my bet is that you
are showing us something other than your actual code.
{
pSMin=pSCurr;

}

pSCurr=pScurr->Snext;

This is the basis of my guess that `person' is an alias for
`struct Sname'. If it were not, the compiler would complain here --
unless both `person' *and* `struct Sname' have an element named
`Snext', which is possible but not especially plausible.
}

return psMin;

What is `psMin'? You've shown us a `pSMin', but that's not the
same thing at all.
} //Error:Expected a declaration! What can I do to make this work?

Could somebody please write a piece of code that will walk the list?

I could certainly write code that will walk *a* list, but since
I don't see solid evidence in yours of the existence of anything one
might call *the* list, then no: I cannot write the code. If you need
assistance, please try again -- with the *exact* and *complete* code
that's giving you trouble, and not with an inaccurate paraphrase.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Hello and Help please :-) 1
linked list 26
Reversing a linked list 116
doubly-linked list & sorting 5
linked list problem 11
URGENT 1
Problem with scanf 7
Thread-Safe Generic List Queue in C 7

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top