Thread: looking for source code

  1. #1
    Registered User ph071's Avatar
    Join Date
    Dec 2008
    Posts
    5

    looking for source code

    hi everyone

    just was reading the tutorials on C on the site and wanted to know a lot more how the coding works i think that my studying the source code of a program will gain me more understanding in how all the small strings of statements and condition works.

    Just need some source code on "loops" and "if statement" please

    maybe any small projects that use this and can be understood by a beginner

    Please
    Thankyou

  2. #2
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    Code:
    int i;
    for (i = 0; i < 10; i++) {
         if (i &#37; 2 == 0) {
              printf("%d\n", i);
         }
    }

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Code:
    int main () {
    	int i=0;
    	while (i<11) {		// if statement in loop
    		if (i&#37;2>0) puts("Odd number in loop.");
    		i++;
    	}
    	return 0;
    }
    after noticing cyberfish's post: That is kind of an erie inversion with the modulus...I am going to make sure there is no cyberfish under my bed...
    Last edited by MK27; 12-06-2008 at 10:04 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  4. #4
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    477
    Quote Originally Posted by MK27 View Post
    Code:
    int main () {
    	int i=0;
    	while (i<11) {		// if statement in loop
    		if (i%2>0) puts("Odd number in loop.");
    		i++;
    	}
    	return 0;
    }
    after noticing cyberfish's post: That is kind of an erie inversion with the modulus...I am going to make sure there is no cyberfish under my bed...
    Remainder of a division by two can only be 1 or zero, never higher.
    "What's up, Doc?"
    "'Up' is a relative concept. It has no intrinsic value."

  5. #5
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    1 is greater than 0.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  6. #6
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    and it also does not equal 0...

    What are you trying to say here?

  7. #7
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by cyberfish View Post
    and it also does not equal 0...

    What are you trying to say here?
    I think I meant 1>0, I'm not sure...
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  8. #8
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    err okay fine.

  9. #9
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by cyberfish View Post
    err okay fine.
    What MK27 meant to say, but was too polite to do so, was that IceDane misread his code, is all.

  10. #10
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    Ah I see.

    I think what IceDane meant is, since the mod can only be 0 or 1, a "==" works as well as a ">", which I think was in reply to this:
    That is kind of an erie inversion with the modulus...I am going to make sure there is no cyberfish under my bed...
    which I also don't quite get.

  11. #11
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    477
    Quote Originally Posted by cyberfish View Post
    Ah I see.

    I think what IceDane meant is, since the mod can only be 0 or 1, a "==" works as well as a ">", which I think was in reply to this:

    which I also don't quite get.
    Yeah, you're right. Just making sure you weren't misunderstanding the math. I'm a pedantic above all others.
    "What's up, Doc?"
    "'Up' is a relative concept. It has no intrinsic value."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 08:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM