linked list example

B

Barry Schwarz

Ok I'll try this that's not random. p 143 ¶ 3 §6.6.

for(hashval=0;*s!='\0';s++)

One of your problems is that it is on page 144, not 143. It is
section 6.6 but I have no idea what the "¶ 3" is supposed to
represent.
Why is *s not just s? This speaks of arrays. When I think of linked lists I
don't think of arrays except arrays of structs. I will work with nlist,
lookup, and install and try to figure them out. It might work. But do I
understand what I'm doing? I guess I'll see.

Good to see you take the advice against guessing seriously. And the
answer to your question is obviously no.
 
B

Barry Schwarz

#include <stdio.h>
#include <string.h>

struct nlist {
struct nlist *next;
char *name;
char *def;
};

static struct nlist *hashtab[101]; /* What's this? A declared array

to pointer? What's its purpose */

Why are you working from page 144 when you have not yet understood
section 5.12, starting on page 122, where this is particular example
is described and a general procedure is discussed? One more time:-
The chapters in the book build on knowledge discussed in previous
chapters. Do not move on to the next chapter until you understand the
stuff in the current chapter and successfully complete all the
exercises.
unsigned hash(char *s)
{
unsigned hashval;
for (hashval = 0; *s != '\0'; s++) /*Indent gives me an old style

error here */

You have a compiler which is indentation sensitive!?!? Care to tell
us which one?

How many times have you been told to quote the error message? BTW,
what is the difference between an old style error and a new style
error?
hashval = *s + 31 * hasval;

Is there some reason you cannot be bothered to proofread when you copy
code. Did you not get an error message because hasval is an
undeclared variable? Or is this not the code you actually compiled?
return hashval % 101;
}

Another attempt.

One has to wonder, attempt at what other than trolling?
 
J

jacob navia

Barry Schwarz a écrit :
One has to wonder, attempt at what other than trolling?

He is doing that since several YEARS with great success. There will be
always a moron that will answer his "questions"... and there we go.
 
B

Ben Bacarisse

Kenneth Brody said:
"p", being declared in global space, was initialized to NULL.
Therefore, the loop will never be executed.

The definition we can see is no more than a tentative definition. If
no definition with an explicit initialisation is seen by the end of the
translation unit then, yes, p will be initialised to a null pointer, but
p could be initialised in "c.h" to something that is not null without
there being any conflict with what we can see of the program.
 
B

Bill Cunningham

I think I am just going to read kandr2 from chapter 1 to the end. Do the
excercises and if I have any questions about them ask. But I'm still because
of lack of experience as others have; ask questions.

Bill
 
O

osmium

Bill Cunningham said:
I think I am just going to read kandr2 from chapter 1 to the end. Do
the excercises and if I have any questions about them ask. But I'm still
because of lack of experience as others have; ask questions.

I realize you hardly ever, if ever, listen to advise. Nevertheless.

Put K&R away on a shelf so high you need a ladder to get at it. Buy a book
designed for someone with very little programming background. Use that as a
base for your future studies. I have no personal experience with it but the
book by King in the link would be my starting point.

K&R is by far the best book on C ever written, but it assumes a mind set
that you simply do not have. After a few months with your new book,
whatever it is, you can retrieve K&R from the high shelf.

http://www.amazon.com/C-Programming...=sr_1_1?ie=UTF8&s=books&qid=1276626553&sr=1-1
 
J

James Dow Allen

[snip]

Sorry for going off-topic, but I know some c.l.c.'ers
enjoy finding bugs, and I just noticed a "new" one
(albeit unrelated to C language?).

When I examine this thread ("Re: linked list example",
changing to "Starting over...") using GoogleGroup's
"View as Tree" option, I am able to see only the first
ten messages. For the subsequent message clumps, all
that appears where 10 messages should appear is the
trailer: "Create a group etc." The title changes to
"[no subject]"

My guess is that one of the messages in this thread has
a string that looks like HTML, that Google's "clever"(?)
algorithm overlooked it, and that causes these messages
to disappear as though they were inside an HTML tag.
But I am too lazy to determine whether I am competent
enough to confirm or refute this hypothesis.

Using "Standard View" I do see all messages of the thread.

Sorry for going off-topic, but
(a) some c.l.c.'ers *enjoy* solving such puzzles, and
(b) if this does yield a recipe for foiling readers
of Google Groups, I suppose some Usenetters will be
thankful! :) ...

James Dow Allen
 
N

Nick Keighley

 void Lf_free(Lf_type *node)
 {Lf_type *nextNode;

  while(1)
      {if(node==0)  break;
       nextNode= node->next;
       free(node);
       node    = nextNode;
      }
 }

why use while(condition){}?

all is easier with while(1){if(conditions)  break;}

void Lf_free(Lf_type *node)
{Lf_type *nextNode;

loop:
if(node==0) goto end_loop;
nextNode= node->next;
free(node);
node = nextNode;
goto loop;
end_loop:
}

why use while() {}?

all is easier with goto loop

or drop the loop

void Lf_free(Lf_type *node)
{
Lf_type *nextNode;
if (node==0) return;
nextNode = node->next;
free(node);
Lf_free (nextNode);
}
 
M

Moi

void Lf_free(Lf_type *node)
{Lf_type *nextNode;

loop:
if(node==0) goto end_loop;
nextNode= node->next;
free(node);
node = nextNode;
goto loop;
end_loop:
}

why use while() {}?

all is easier with goto loop

or drop the loop

void Lf_free(Lf_type *node)
{
Lf_type *nextNode;
if (node==0) return;
nextNode = node->next;
free(node);
Lf_free (nextNode);
}


I think you forgot one:

void Lf_free(Lf_type *node)
{
if (!node) return;
Lf_free(node->next);
free(node);
}

;-)

HTH,
AvK
 
N

Nick Keighley

I think you forgot one:

void Lf_free(Lf_type *node)
{
  if (!node) return;
  Lf_free(node->next);
  free(node);

}

;-)

who's going to explain it to bill...
 
B

BruceS

 [snip]

Sorry for going off-topic, but I know some c.l.c.'ers
enjoy finding bugs, and I just noticed a "new" one
(albeit unrelated to C language?).

When I examine this thread ("Re: linked list example",
changing to "Starting over...") using GoogleGroup's
"View as Tree" option, I am able to see only the first
ten messages.  For the subsequent message clumps, all
that appears where 10 messages should appear is the
trailer: "Create a group etc."  The title changes to
"[no subject]"

My guess is that one of the messages in this thread has
a string that looks like HTML, that Google's "clever"(?)
algorithm overlooked it, and that causes these messages
to disappear as though they were inside an HTML tag.
But I am too lazy to determine whether I am competent
enough to confirm or refute this hypothesis.

Using "Standard View" I do see all messages of the thread.

Sorry for going off-topic, but
(a) some c.l.c.'ers *enjoy* solving such puzzles, and
(b) if this does yield a recipe for foiling readers
of Google Groups, I suppose some Usenetters will be
thankful!   :)  ...

It gets better. With it set to "sort by reply", I get that result
when I choose *any* post in the thread, even the first. The view only
works when you select the thread without selecting any posts. If you
select "sort by date", it seems to work as well as GG ever works.
My main reason for using GG is portability. I want to be able to read
and post to the same ng's from different locations/OSs and be able to
see what posts are "new". Is there a better way?
 
B

Bill Cunningham

osmium said:
I realize you hardly ever, if ever, listen to advise. Nevertheless.

[snip]

I appreciate the advice I get and alot of it runs contrary to other
advice i get. So I must try something and keep the advice in mind. I was
recently give advice not to write code with commas,

int a,b,c;

But write 3 separate lines with no explaination as to why I should do
that and how important the opinion to me was. The code is obviously not
going to be affected one way or the other.

Bill
 
B

Barry Schwarz

who's going to explain it to bill...

Bill has already accomplished his goal: getting a bunch of people who
should know better, including me, to join the discussion.
 
N

Nick Keighley

Sorry for going off-topic, but I know some c.l.c.'ers
enjoy finding bugs, and I just noticed a "new" one
(albeit unrelated to C language?).
When I examine this thread ("Re: linked list example",
changing to "Starting over...") using GoogleGroup's
"View as Tree" option, I am able to see only the first
ten messages.  For the subsequent message clumps, all
that appears where 10 messages should appear is the
trailer: "Create a group etc."  The title changes to
"[no subject]"
My guess is that one of the messages in this thread has
a string that looks like HTML, that Google's "clever"(?)
algorithm overlooked it, and that causes these messages
to disappear as though they were inside an HTML tag.
But I am too lazy to determine whether I am competent
enough to confirm or refute this hypothesis.
Using "Standard View" I do see all messages of the thread.
Sorry for going off-topic, but
(a) some c.l.c.'ers *enjoy* solving such puzzles, and
(b) if this does yield a recipe for foiling readers
of Google Groups, I suppose some Usenetters will be
thankful!   :)  ...

It gets better.  With it set to "sort by reply", I get that result
when I choose *any* post in the thread, even the first.  The view only
works when you select the thread without selecting any posts.  If you
select "sort by date", it seems to work as well as GG ever works.
My main reason for using GG is portability.  I want to be able to read
and post to the same ng's from different locations/OSs and be able to
see what posts are "new".  Is there a better way?- Hide quoted text -

I can no longer read most of this thread with google. Even using
"Standard View". If anyone wants me to read their response to my last
post they'll have to post in a new thread.
 
C

Chad

We are on topic in this thread.
It is in fact the case that I once
corrected somebody who tried to correct Bill
when Bill was right.
The topic was the representation of a null character.

I'm not here to teach C,
there's an alt.learn group for that.
I'm here to discuss C for the purpose
of increasing my own familiarity with C.

That's why Bill doesn't bother me in the least.


Maybe it's just me, but I guess I want to learn C by reading this
forum, as opposed to say, going to a slightly easier forum. What can I
say, I enjoy the self abuse. This behavioral pattern stems from high
school. I took standard level chemistry in 11th grade and actually
managed to fail the class. I figured I wasn't motivated enough, and
hence why I managed to fail. So my senior year, I decided to put this
theory to the test, and signed up for the hardest science class in our
district. At the time, this was calculus based physics. This was the
only time that I ever managed to get above a C in any grade school
science class.
 

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

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,209
Latest member
NelsonJax

Latest Threads

Top