If condition

This is a discussion on If condition within the C Programming forums, part of the General Programming Boards category; How the if condition works here????????? Code: void main() { int i; char a[]="

Thread: If condition

"; if(printf("%s\n",a)) printf("Ok here \n"); else printf("Forget ...

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    46

    If condition

    How the if condition works here?????????

    Code:
    void main()
    {
    	int i;
    	char a[]="\0";
    	if(printf("%s\n",a))
    		printf("Ok here \n");
    	else
    		printf("Forget it\n");
    }

  2. #2
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,425
    are you testing any condition here? i think you should go and review some example snippets and just google usage / construction of if statements.
    Last edited by rogster001; 09-02-2009 at 03:06 AM.

  3. #3
    The larch
    Join Date
    May 2006
    Posts
    3,573
    printf returns the number of characters printed. Since it prints '\n', the result is one and the condition is always true.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,543
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. condition variable on read/write locks
    By ShwangShwing in forum C Programming
    Replies: 3
    Last Post: 04-29-2009, 09:32 AM
  2. Condition variables
    By sethjackson in forum Windows Programming
    Replies: 16
    Last Post: 03-19-2008, 11:42 AM
  3. SDL Condition variables.
    By antex in forum Game Programming
    Replies: 3
    Last Post: 11-11-2005, 06:11 AM
  4. Looping condition
    By Chaplin27 in forum C++ Programming
    Replies: 3
    Last Post: 05-29-2005, 02:06 PM
  5. Race condition
    By Roaring_Tiger in forum C Programming
    Replies: 5
    Last Post: 10-24-2004, 09:42 PM

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