473,667 Members | 2,562 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(Relati ons *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 2673
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(Relati ons *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(Relati ons *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
2146
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
11453
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 which will detect the loop but I am stumped how one would remove this loop. Any ideas? typedef enum { FALSE, TRUE } bool;
12
15088
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 should be kept for references to previous element of list. Here is my solution below: struct node {
4
3598
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; };   struct pcb *pcb_pointer;
6
2231
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() command. Any thoughts?
3
3319
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 list called NAMES which will contain all C like identifiers of less than 256 characters long identified in the input file F. Each identifier will be represented by a triple (I, length, string) where I is used to identify the type of
1
4153
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 linked lists as follows: (a) A double linked list called NAMES which will contain all C like identifiers of less than 256 characters long identified in the input file F. Each identifier
3
472
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 your assitance in helping me solve this problem. Information: Create 4 double linked lists as follows: (a) A double linked list called NAMES which will contain all C like
4
1903
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 can u suggest how can i avoid it? #include<stdio.h> #include<stdlib.h> #include<ctype.h>
9
4899
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 avail. The function receives a string from main and then inserts in the list the new word in alphabetical order. Here is my function: struct word { // double linked list. Here the list is global and is first built
0
8457
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8365
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8788
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8563
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7390
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6203
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2776
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2013
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.