while loop.. do while..?

This is a discussion on while loop.. do while..? within the C Programming forums, part of the General Programming Boards category; Hi everyone... I'm having trouble with a loop... well, I guess the problem is coming from the loop actually. The ...

  1. #1
    Lau
    Lau is offline
    Registered User
    Join Date
    Nov 2002
    Posts
    60

    Angry while loop.. do while..?

    Hi everyone...
    I'm having trouble with a loop... well, I guess the problem is coming from the loop actually.
    The program is compiling, but it seems like the loop is an endless one, and I don't understand why. Here's the code:

    Code:
    void displayInfo(EMP employee[]) {
      int i=0;
      int k=0;
      char temp[MAXLEN];
    
      puts("Enter employee's last name:");
      scanf("%s", temp);
    
      while (temp != employee[i].last_name)
        i++;
    
      printf("Employee ID: %d\n", employee[i].ID);
      printf("Employee last name: %s\n", employee[i].last_name);
      printf("Employee first name: %s\n", employee[i].first_name);
      printf("Employee department: %s\n", employee[i].dept);
      printf("Employee salary: $%.2f\n", employee[i].salary);
    
      puts("What else do you want to do? ");
      return;
    }
    I'm sure I'm doing something stupid, but it really looks good to me... If you could help me out here...
    Last edited by Lau; 11-11-2002 at 02:21 PM.

  2. #2
    Lau
    Lau is offline
    Registered User
    Join Date
    Nov 2002
    Posts
    60
    Thanks Salem... I'm going to try that right now.

    Although, when you compare strings, is that how it has to be done ALL THE TIME? (yes yes, I'm new to C!! lol )

  3. #3
    Lau
    Lau is offline
    Registered User
    Join Date
    Nov 2002
    Posts
    60
    That works for me!!! Thank you...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. nested loop, simple but i'm missing it
    By big_brother in forum C Programming
    Replies: 19
    Last Post: 10-23-2006, 10:21 PM
  2. While loop misbehaving (or misunderstanding)
    By mattAU in forum C Programming
    Replies: 2
    Last Post: 08-28-2006, 02:14 AM
  3. loop in a linked linked lists
    By kris.c in forum C Programming
    Replies: 6
    Last Post: 08-26-2006, 12:38 PM
  4. while loop help
    By bliznags in forum C Programming
    Replies: 5
    Last Post: 03-19-2005, 11:30 PM
  5. loop issues
    By kristy in forum C Programming
    Replies: 3
    Last Post: 03-05-2005, 08:14 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21