Thread: Urgent help on 3d Array

  1. #16
    LonelyPlanetWa
    Guest

    Talking just a suggestion..and 1 question!

    OK so since u mentioned in one of your first posts that the size of the array (no. of employees) depends on how many employees the user wishes to input, you could ask the user to input that number right in the beginning & store it in your variable 'size'...

    ...which actually, i think, leads me to my question...what does the '2' signify in:

    while ( scanf("%s%d", staffname[count], &staffnumber[count]) == 2 )

    got anything to do with eof?...please advise...

  2. #17
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231

    Re: just a suggestion..and 1 question!

    Originally posted by LonelyPlanetWa
    >you could ask the user to input that number right in the beginning & store it in your variable 'size'...
    Yes you could, but then the array size becomes dynamic, meaning you need to start malloc'ing memory. That's a lesson for another day

    >what does the '2' signify in:
    >while ( scanf("%s%d", staffname[count], &staffnumber[count]) == 2 )
    It is the number of input arguments for which values were successfully scanned and stored. Basically, here we are scanning for %s and %d. If we successfully read one string followed by one int, scanf()'s return code will be 2, and all will be well. If we only read the string (say for example the users enters a letter where they should have entered the number), the return will be 1.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. array of pointers/pointer arithmetic
    By tlpog in forum C Programming
    Replies: 18
    Last Post: 11-09-2008, 07:14 PM
  2. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  3. 3D Array of Bool
    By cybernike in forum C++ Programming
    Replies: 37
    Last Post: 06-28-2007, 11:17 AM
  4. Replies: 1
    Last Post: 01-11-2002, 11:22 PM
  5. 3D Array
    By Alextrons in forum Windows Programming
    Replies: 4
    Last Post: 01-11-2002, 01:39 AM