Thread: C language program

  1. #1
    Registered User
    Join Date
    Aug 2012
    Posts
    2

    C language program

    Need code of this Program:
    1. This program displays a running counter starting from 0 till infinity. The counter starts/resets by pressing
    enter and stops by pressing some other key. Use as many define directives and macros to achieve this
    task. The counter when played should be like a real counter (no separate line should be used for the
    next counter increment). Hint: use clrscr() command inside the for loop.



  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Welcome to the C forum, Roza!

    We don't write programs on request, however. What we do is help YOU get over anything that you're stuck on, in the program.

    With rare exceptions, you will need to start the program, and then ask your specific questions about whatever has you perplexed, in the program.

    If I may add, your program is very likely to show a flashing screen (alternately printing and clearing the monitor), if you put a clrscr() inside a simple counter display loop. What you might see could be different, since it depends on the speed of your cpu and graphics display hardware.

    to proceed:

    1) Start your program, making sure you meet the requirements of the assignment. Only you were in the class, and/or reading the assignment, and only you will receive a grade for it. That part, is on you, 100%.

    2) Post up your program, and tell us what is the problem you're having with it.

    3) THEN we can assist you in solving that problem.

  3. #3
    Registered User
    Join Date
    Aug 2012
    Posts
    2
    I have Made a Simple program of it but i have a doubt that i am doing wrong.
    Code:
    #include<stdio.h>
    #include<conio.h>
    
    
    void beep(void);
    int main(void)
    {
         printf("Press enter to start..."); 
         while ('\n'!= getchar ());   
         beep();
         
    }
        void beep(void)
        {
         int n,j;
        
         for(n=1;;n++)
         {
                      printf("%d",n); 
                       
                      for(j=1;j<200000000;j++)
                      ;
                      system("cls");
                     
         }
        
         }

  4. #4
    Registered User
    Join Date
    Apr 2008
    Posts
    396
    What do you mean?
    Just add a \n to flush the output buffer and you're done for the first part (a running counter).
    Code:
    printf("%d\n", n);
    As a side note you could use the standard time primitives clock() and CLOCKS_PER_SEC or time() to set a precise delay between each increment, your loop for(j...) is arbitrary and the result will vary depending on the machine you're running your code on.
    Besides, if you ask the compiler to optimize you code, that loop will be filtered out.
    Last edited by root4; 08-17-2012 at 07:27 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 06-07-2011, 03:30 PM
  2. Calling Assembly Language programs from C++ program
    By EonsNearby in forum C++ Programming
    Replies: 6
    Last Post: 04-23-2011, 04:58 AM
  3. Quick sort in C language (Program required)
    By internet_bug in forum C Programming
    Replies: 4
    Last Post: 09-18-2008, 11:18 PM
  4. Finding out which language a program is written in.
    By billstarks in forum Tech Board
    Replies: 9
    Last Post: 06-07-2007, 06:13 PM
  5. That language do you program in?
    By h3ro in forum A Brief History of Cprogramming.com
    Replies: 28
    Last Post: 04-17-2007, 05:41 PM