Newbie Question. How do you check if array is empty? and a variableis not assigned to anything?

Discussion in 'C Programming' started by chutsu, Jun 2, 2009.

  1. chutsu

    chutsu Guest

    As the title says:
    How do you check if array is empty?
    And also how do you check that a variable is not assigned to
    anything?
     
    chutsu, Jun 2, 2009
    #1
    1. Advertising

  2. chutsu

    Guest

    Re: Newbie Question. How do you check if array is empty? and avariable is not assigned to anything?

    On 2 June, 23:07, Richard Heathfield <> wrote:
    > chutsu said:
    >
    > > As the title says:
    > > How do you check if array is empty?

    >
    > It depends what you mean by "empty". If you think "filled with zero
    > values" means "empty", check each value for 0 to determine whether
    > the array is empty. If you mean something else, what do you mean?
    >
    > > And also how do you check that  a variable is not assigned to
    > > anything?

    >
    > If you mean "how do you check that a variable has not been assigned
    > a value?", you don't. If a variable (or rather, an object) has not
    > been assigned a value, you're not allowed to look at it. All you
    > can do is assign to it. Therefore, you the programmer are supposed
    > to know whether an object has been assigned a value.
    >
    > To make this easier for myself, I try to remember to initialise
    > *everything*, and consider the absence of such initialisation to be
    > a bug in my program. Not everyone agrees with me. In fact, there
    > are some very bright people in this very newsgroup who disagree
    > with me... but I have my reasons (historical, and painful).
    >
    > --
    > Richard Heathfield <http://www.cpax.org.uk>
    > Email: -http://www. +rjh@
    > Forged article? Seehttp://www.cpax.org.uk/prg/usenet/comp.lang.c/msgauth.php
    > "Usenet is a strange place" - dmr 29 July 1999


    But what if your C program requires input from a user. How do you
    check if the user has entered anything at all instead of just pressing
    enter?
    Thanks
    Chris
     
    , Jun 2, 2009
    #2
    1. Advertising

  3. chutsu

    Sjouke Burry Guest

    chutsu wrote:
    > As the title says:
    > How do you check if array is empty?


    Check your program.

    > And also how do you check that a variable is not assigned to
    > anything?


    No variable is ever assigned to anything.

    It can be use for millions of purposes.
     
    Sjouke Burry, Jun 2, 2009
    #3
  4. Re: Newbie Question. How do you check if array is empty? and a variable is not assigned to anything?

    "" <> writes:
    > On 2 June, 23:07, Richard Heathfield <> wrote:
    >> chutsu said:
    >>
    >> > As the title says:
    >> > How do you check if array is empty?

    >>
    >> It depends what you mean by "empty". If you think "filled with zero
    >> values" means "empty", check each value for 0 to determine whether
    >> the array is empty. If you mean something else, what do you mean?

    [...]
    >
    > But what if your C program requires input from a user. How do you
    > check if the user has entered anything at all instead of just pressing
    > enter?


    That's a *very* different question, and it depends on how you're
    reading the input. Richard Heathfield posted some good information.
    You might also take a look at section 12 of the comp.lang.c FAQ,
    <http://www.c-faq.com/>.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Jun 2, 2009
    #4
  5. Re: Newbie Question. How do you check if array is empty? and avariable is not assigned to anything?

    On 2 Jun 2009 at 22:07, Richard Heathfield wrote:
    > If a variable (or rather, an object) has not been assigned a value,
    > you're not allowed to look at it. All you can do is assign to it.


    Typical Heathfield bullshit.

    If you have a static variable, then there is no undefined behavior
    involved in "looking it at" or using it in any other way even before
    you've assigned it a value.
     
    Antoninus Twink, Jun 3, 2009
    #5
  6. chutsu

    Willem Guest

    Re: Newbie Question. How do you check if array is empty? and avariable is not assigned to anything?

    Antoninus Twink wrote:
    ) On 2 Jun 2009 at 22:07, Richard Heathfield wrote:
    )> If a variable (or rather, an object) has not been assigned a value,
    )> you're not allowed to look at it. All you can do is assign to it.
    )
    ) Typical Heathfield bullshit.
    )
    ) If you have a static variable, then there is no undefined behavior
    ) involved in "looking it at" or using it in any other way even before
    ) you've assigned it a value.

    That's because static variables are implicitly assigned zero values.
    So they can't have not been assigned a value.


    SaSW, Willem
    --
    Disclaimer: I am in no way responsible for any of the statements
    made in the above text. For all I know I might be
    drugged or something..
    No I'm not paranoid. You all think I'm paranoid, don't you !
    #EOT
     
    Willem, Jun 3, 2009
    #6
  7. Re: Newbie Question. How do you check if array is empty? and avariable is not assigned to anything?

    On 3 Jun 2009 at 8:19, pete wrote:
    > Willem wrote:
    >> That's because static variables are implicitly assigned zero values.
    >> So they can't have not been assigned a value.

    >
    > Antoninus Twink may be distinguishing between "initialization" and
    > "assignment".


    Exactly so.

    "The word "pedant" is used by people who don't care about correctness to
    describe people who do." (R Heathfield, writing from a glass house
    somewhere in England)
     
    Antoninus Twink, Jun 3, 2009
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Gagon

    If you could add anything you want

    John Gagon, May 12, 2006, in forum: Java
    Replies:
    55
    Views:
    1,444
    Oliver Wong
    May 25, 2006
  2. Marcia Hon

    Check if a directory is empty and empty it

    Marcia Hon, Feb 8, 2004, in forum: C Programming
    Replies:
    8
    Views:
    611
    Dave Thompson
    Feb 14, 2004
  3. Jean-Daniel Gamache

    global variable not assigned, newbie question

    Jean-Daniel Gamache, Nov 1, 2004, in forum: Python
    Replies:
    2
    Views:
    339
    Peter Hansen
    Nov 2, 2004
  4. ButlerDJIAM
    Replies:
    0
    Views:
    580
    ButlerDJIAM
    Nov 9, 2006
  5. Mumia W. (reading news)
    Replies:
    4
    Views:
    141
    Mumia W. (reading news)
    Nov 20, 2006
Loading...

Share This Page