473,326 Members | 2,148 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

double while loop in linked list

hi,

the following while function(it´s supposed to find word synonyms out of a
list) always quits after running through the list in the inner loop once.
it´s like the aktuell = aktuell->next on the bottom would not be there.
can anyone tell me what the problem might be?

greetz,

bastian
int checksyn(Relations *head)
{
char rel = 'S';
Relations *aktuell = head;
Relations *aktuell2 = head;

while (aktuell != NULL)
{
if(aktuell->relType == rel)
{
while (aktuell2 != NULL)
{
if(aktuell2->relType == rel && aktuell2->word == aktuell->dest &&
aktuell->word == aktuell2->dest)

printf("match found for: %c %s %s\n",aktuell->relType, aktuell->word,
aktuell->dest);
else
printf("no match found for: %c %s %s\n", aktuell->relType, aktuell->word,
aktuell->dest);
aktuell2 = aktuell2->next;
}

}
aktuell = aktuell->next;
}
return 0;
}

Nov 14 '05 #1
3 2647
picknicker187 wrote:
hi,

the following while function(it´s supposed to find word synonyms out of a
list) always quits after running through the list in the inner loop once.
it´s like the aktuell = aktuell->next on the bottom would not be there.
can anyone tell me what the problem might be?

greetz,

bastian
int checksyn(Relations *head)
{
char rel = 'S';
Relations *aktuell = head;
Relations *aktuell2 = head;

while (aktuell != NULL)
{
if(aktuell->relType == rel)
{
Once you've run througgh the inner loop, `aktuell2' is NULL. while (aktuell2 != NULL)
{
if(aktuell2->relType == rel && aktuell2->word == aktuell->dest &&
aktuell->word == aktuell2->dest)

printf("match found for: %c %s %s\n",aktuell->relType, aktuell->word,
aktuell->dest);
else
printf("no match found for: %c %s %s\n", aktuell->relType, aktuell->word,
aktuell->dest);
aktuell2 = aktuell2->next;
}

}
aktuell = aktuell->next;
}
return 0;
}

HTH,
--ag

BTW - please post appropriately indented code (spaces, not tabs).

--
Artie Gold -- Austin, Texas

"If you don't think it matters, you're not paying attention."
Nov 14 '05 #2
picknicker187 wrote:
the following while function(it´s supposed to find word synonyms out of a
list) always quits after running through the list in the inner loop once.
it´s like the aktuell = aktuell->next on the bottom would not be there.
can anyone tell me what the problem might be?


You need to restart aktuell2 before the inner while() loop.

'aktuell = aktuell->next;' is working fine.
The problem is that

while (aktuell2 != NULL) { /* ... */ }

never goes inside the loop the second (or later) time around.

[un-indented code snipped]

Do a favor to us and, especially, to yourself: indent your code.
--
================== My mail address is spam-trapped ==================
If my name is not in the "To:" line; or if you send a "Content-Type:"
different than "text/plain" (optionally followed by anything); or
if message size is greater than 10K -- your mail _will_be_ /dev/null'ed
Nov 14 '05 #3
picknicker187 wrote:
hi,

the following while function(it´s supposed to find word synonyms out of a
list) always quits after running through the list in the inner loop once.
it´s like the aktuell = aktuell->next on the bottom would not be there.
can anyone tell me what the problem might be?

greetz,

bastian
int checksyn(Relations *head)
Please post the prototype of Relations.
or better, a compilable code.
{
char rel = 'S';
Relations *aktuell = head;
Relations *aktuell2 = head;

while (aktuell != NULL)
{
if(aktuell->relType == rel)
{
while (aktuell2 != NULL)
{
if(aktuell2->relType == rel && aktuell2->word == aktuell->dest &&
aktuell->word == aktuell2->dest)
Well - I am guessing that the members word and dest are
pointers to characters, from the next line .

Assuming that, aktuell->word == aktuell2->dest may not be what you
want in the previous line. It is comparing pointers, instead of
two C-strings. You may want 'strcmp' .

printf("match found for: %c %s %s\n",aktuell->relType, aktuell->word,
aktuell->dest);


--
Karthik. http://akktech.blogspot.com .
' Remove _nospamplz from my email to mail me. '
Nov 14 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

32
by: Carson | last post by:
Hi , Is there a very efficient way to set a double array to 0 ? (I have tried memset, but the result doesn't look correct.) Carson
5
by: Jani Yusef | last post by:
Based on an interview question I heard of but did not know the answer to....... How do you find and remove a loop from a singly linked list? In a google groups search I found the following code...
12
by: Eugen J. Sobchenko | last post by:
Hi! I'm writing function which swaps two arbitrary elements of double-linked list. References to the next element of list must be unique or NULL (even during swap procedure), the same condition...
4
by: JS | last post by:
I have a file called test.c. There I create a pointer to a pcb struct: struct pcb {   void *(*start_routine) (void *);   void *arg;   jmp_buf state;   int    stack; }; ...
6
by: deanfamily | last post by:
I am re-posting my second problem. I have a double-linked list. I need to know if it is possible to remove just one of an item, instead of all that match the given criteria with the remove()...
3
by: Little | last post by:
Could someone help me get started on this program or where to look to get information, I am not sure how to put things together. 1. Create 4 double linked lists as follows: (a) A double linked...
1
by: Little | last post by:
Could someone help me figure out how to put my project together. I can't get my mind wrapped around the creation of the 4 double Linked Lists. Thank your for your insight. 1. Create 4 double...
3
by: Little | last post by:
Could someone tell me what I am doing wrong here about declaring mutiple double linked lists. This is what the information is for the project and the code wil be below that. Thank your soo much for...
4
by: peo_leo | last post by:
I have a simple implementation of double linked list this code is crashing if i enter values not present in the linked list(during insertion) or if i try to delete values not present in the list...
9
by: Sheldon | last post by:
Hi, I am trying to understand linked lists and the different ways to write a linked list and double linked list. I have been trying to get this function called insert_word to work but to no...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.