hi can any one say how does this program works

This is a discussion on hi can any one say how does this program works within the C Programming forums, part of the General Programming Boards category; Code: #include<stdio.h> #include<conio.h> int main() { int c; clrscr(); for(c=0;c<10;c++) { printf("&#37;*d\n",c,c); } getch(); return 0; }...

  1. #1
    Registered User
    Join Date
    Oct 2008
    Location
    vizag
    Posts
    2

    Wink hi can any one say how does this program works

    Code:
    #include<stdio.h>
    #include<conio.h>
    int main()
    {
    	int c;
    	clrscr();
    	for(c=0;c<10;c++)
    	{
    		printf("&#37;*d\n",c,c);
    	}
    	getch();
    	return 0;
    }
    Last edited by Salem; 10-25-2008 at 09:08 AM. Reason: Snipped email address

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    I'm going to guess the output looks like this:

    Code:
    0
     1
      2
       3
        4
    [..etc]
    I have never used conio.h but presumably this is a library of console functions including clrscr().
    The for loop uses the incrementing c value as the padding in the printf. If it read printf("% 3d\n",c,c); the output would be:

    Code:
       0
       1
       2
       3
       4
    [..etc]
    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

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,304
    It works by calling various C library routines to change what is seen in the console window. I'm guessing that this answer is about as useful as your question.

    If you're not simply asking for someone else to provide the comments for a program which you copied off someone else, rather than writing it yourself, then please ask a more specific question.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program works on Windows XP and 2000, not on 98 or ME
    By MidnightlyCoder in forum C++ Programming
    Replies: 7
    Last Post: 03-10-2006, 02:36 PM
  2. My program works but the numbers are not correct.
    By romeoz in forum C++ Programming
    Replies: 4
    Last Post: 07-22-2003, 10:02 PM
  3. Replies: 3
    Last Post: 01-14-2003, 09:34 PM
  4. Enistine program
    By Mac_the vamp in forum C Programming
    Replies: 2
    Last Post: 11-11-2002, 09:56 AM
  5. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 11:39 AM

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