Thread: if-else statement condition

  1. #16
    Registered User
    Join Date
    May 2009
    Instead of
    In the future, remember an array name is the address of the array; so no need most of the time to put an address operator (&) in front of it.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  2. #17
    Registered User
    Join Date
    May 2012
    Quote Originally Posted by YouMe View Post
    I'm not understand, can you show where is it to correct it?..i mean an example
    If you declare a variable like
    int x;
    the compiler just allocates enough memory to store a value of this type, but it doesn't clear the memory. So whatever value is stored at this memory location is still there (probably just garbage).

    int x = 0;
    initializes the variable x to 0 and then you can be sure that this value stays there as long as you don't change it.

    The problem in your code is that
    if(list[i].name != NULL)
    compares the pointer "list[i].name" to the pointer "NULL" and the result is always true because all elements of list have a valid memory address and thus they are unequal to NULL. What you want is to compare the value the pointer "list[i].name" points to to a value which denotes an empty string (usually '\0' as the only character in the string). But you have to initialize your list-array to be able to do this.

    I also suggest reading a tutorial about pointers, arrays and strings.

    Bye, Andreas

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to implement this condition..
    By dswartz2 in forum C Programming
    Replies: 11
    Last Post: 05-23-2011, 02:01 PM
  2. if condition
    By jgtech in forum C Programming
    Replies: 1
    Last Post: 04-12-2011, 05:25 AM
  3. If condition
    By rits in forum C Programming
    Replies: 3
    Last Post: 09-02-2009, 05:54 AM
  4. Complicated Condition
    By zmi in forum C++ Programming
    Replies: 4
    Last Post: 05-05-2009, 06:15 PM
  5. c++ condition use? how u use it? help
    By mikeasianlee in forum C++ Programming
    Replies: 4
    Last Post: 12-06-2004, 09:44 PM