Thread: looping problem

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    31

    looping problem

    Ok.very weird problem. Thanks to whoever can helpme here.

    I have these double linked lists defined properly and working fine. I call them "pNode", and "pNode3".

    The data inside pNode contains strings of words that I gathered from a text file.

    Now, I need to start from the head of the pNode (I called it pHead) and go until end of the line 1 AND add all the data from pNode to pNode3 (I do the add with adddll3 function....

    Now the problem starts.... on second itteration, I need to add the data from line 2 of pNode to pNode3... such that pNode3 now contains only the data of line 2 of pNode.......

    It is done until there is no more data .......


    What the following does is .. it takes in line 1 on 1st iteration, then line 1 &2 on second iteration, then line 1,2,3 on 3rd iteration.... and so forth. I need to take in line 1 for 1st, then on second line 2 such that the contents of the Pnode3 is overwritten with this content.......

    please help me

    Code:
    pNode=pHead;
    pNode3=PHead3;
    
    for(pNode;pNode!=EOF ; pNode=pNode->pNext)
    {
            for(pNode;strcomp(pNode->nData,newlinetest)!=0;pNode=pNode->pNext)
           {
                adddll3(pNode->nData);
            }
      
                    printf("\n******** \n");
    
                    display3(pNode3);
                    printf("\n");
     }
    the display function just displays everything inside the the pNode3....
    Last edited by swagatob; 10-12-2004 at 08:25 AM.

  2. #2
    Registered User
    Join Date
    Oct 2004
    Posts
    31
    pelase help me... I am desperate.... thnks

  3. #3
    Registered User
    Join Date
    Jun 2003
    Posts
    361
    What does your adddll3() function look like?
    Is newlinetest just a char set to '\n'?

  4. #4
    Registered User
    Join Date
    Oct 2004
    Posts
    31
    Code:
       char *newlinetest=malloc(100*sizeof(char));
        strcpy(newlinetest,"\n");
    this is my newline test


    Code:
    void adddll3(char *ch2)
    {
        pNode3 = malloc (sizeof (struct NODE2));
        pNode3->nData = ch2;
        if (pHead3 == NULL) { /*pHead 3 i just the head pointer for pNode3*/
            pHead3 = pNode3;
            pNode3->pPrev  = NULL; /*pPrev and pNext are the previous and next pointer in the structure def of the double linked list*/
        }
        else {
            pTail3->pNext = pNode3; /*pTail3 is just the Tail pointer of double linked list pNode3*/
            pNode3->pPrev = pTail3;
        }
        pTail3  = pNode3;
        pNode3->pNext = NULL;
    
    }

  5. #5
    Registered User
    Join Date
    Oct 2004
    Posts
    31
    Code:
    /*structure of the double linked list*/
    struct NODE2
    {
        struct NODE2 *pNext;
        struct NODE2 *pPrev;
        char* nData;
    }*pHead, *pTail, *pNode, *pHead3,*pTail3,*pNode3;

  6. #6
    Registered User
    Join Date
    Jun 2003
    Posts
    361
    strcpy(newlinetest,"\n");
    Double quotes, I.e. " " represent a string, so your newlinetext variable is equal to:
    newlinetest[0] = '\'
    newlinetest[1] = 'n'

    Try changing the double quotes, to single quotes, I.e. '\n'
    Single quotes are meant to represent characters (in the case, the newline character).

    I believe (for what I think you're trying to do) that this change is needed. Don't know if it will solve your problem, but it was just the first thing I noticed. I'm gonna keep looking here some more...

  7. #7
    Registered User
    Join Date
    Jun 2004
    Posts
    722
    Quote Originally Posted by Epo
    strcpy(newlinetest,"\n");
    Double quotes, I.e. " " represent a string, so your newlinetext variable is equal to:
    newlinetest[0] = '\'
    newlinetest[1] = 'n'

    Try changing the double quotes, to single quotes, I.e. '\n'
    Single quotes are meant to represent characters (in the case, the newline character).

    I believe (for what I think you're trying to do) that this change is needed. Don't know if it will solve your problem, but it was just the first thing I noticed. I'm gonna keep looking here some more...
    Wrong!

    strcpy(newlinetest,"\n");
    variable is equal to:
    newlinetest[0] = '\n'
    newlinetest[1] = 0

    \n is interpreted by the compiler as an escape sequence. These escape sequences represent a character. \n means 13 ascci which is a newline.

  8. #8
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    for(pNode;pNode!=EOF ; pNode=pNode->pNext)
    What the hell are you doing?

    If you're looking for help, you're going about it horribly wrong:
    1) Your variable and function names are horrible.
    2) You gave a horrible description of the problem.
    3) Likewise, a horrible description of what it is you're trying to do.
    4) Furthermore, a horrible description of what your nodes contain.
    5) It's horrible that I can't find more ways to call this horrible.

    What exactly does nData contain? Multiple lines? One line? Do you have a linked list where each node contains a single line? Are you trying to concatenate all of them into a single node? What exactly?

    This should be trivially easy to fix, however, I have no idea what it is you're trying to do.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Words and lines count problem
    By emo in forum C Programming
    Replies: 1
    Last Post: 07-12-2005, 03:36 PM
  2. looping problem
    By chris285 in forum C++ Programming
    Replies: 4
    Last Post: 04-22-2005, 11:03 AM
  3. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM
  4. binary tree problem - help needed
    By sanju in forum C Programming
    Replies: 4
    Last Post: 10-16-2002, 05:18 AM
  5. Looping problem
    By sketchit in forum C Programming
    Replies: 2
    Last Post: 10-01-2001, 02:19 PM