Thread: comparing strings in linked list

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    23

    comparing strings in linked list

    basically, im trying to get my program to print list of students with a specified year. for example, if the specified year = junior, then the program will print all the junior students in the list.

    however, my program only prints out the first Junior student in list and stops afterwards. what is wrong with my function.

    Heres the code for my function. Thanks in advance.

    Code:
    void printStudentsOfYear(STUDENTNODE* head, char * year)
    {
          // add your code
            STUDENTNODE* currNode = head;
            printf("-----DUMPING STUDENTS OF YEARS------\n");
            while(currNode != NULL)
            {
                    STUDENT* Student = currNode->student;
                    int cmp = strcmp(year,Student->year);
                    if (cmp == 0) {
                            printf("%s, %s, %d\n", Student->name, Student->ucinetid, Student->year, Student->studentid);
                            currNode = currNode->next;
                    }
            }
    }

  2. #2
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Can you post the whole code here, I mean how are you calling, with what parameters etc?
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  3. #3
    Registered User
    Join Date
    Apr 2009
    Posts
    23
    nvm i figured it out, but thanks anyways.

  4. #4
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    What was the problem? Was it with the function you gave or something else?
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  5. #5
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    - printf() has more parameters than format specifiers
    - currNode doesn't get updated if the name doesn't match - so no traveling the linked list

  6. #6
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Quote Originally Posted by nonoob View Post
    - printf() has more parameters than format specifiers
    - currNode doesn't get updated if the name doesn't match - so no traveling the linked list
    Ohh... I just didn't see the printf thing.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. circular doubly linked list help
    By gunnerz in forum C++ Programming
    Replies: 5
    Last Post: 04-28-2007, 08:38 PM
  2. Anyone good with linked list.....I am not....
    By chadsxe in forum C++ Programming
    Replies: 11
    Last Post: 11-10-2005, 02:48 PM
  3. singly linked to doubly linked
    By jsbeckton in forum C Programming
    Replies: 10
    Last Post: 11-06-2005, 07:47 PM
  4. How to use Linked List?
    By MKashlev in forum C++ Programming
    Replies: 4
    Last Post: 08-06-2002, 07:11 AM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM