Thread: run time error

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    32

    run time error

    the following code compiles sucsessfully but gives a runtime error!

    Code:
    #include<stdio.h>
    #include<conio.h>
    main()
    {
    int i,j,k;
    clrscr();
    i=2;j=1;k=0;
    if((i<0)&&(j<i)&&(k=2))
        printf("\n%d",k);
    else
        printf("0");
    if((i>2)||(i>1)||(k=1))
        printf("\n%d",k);
    else
        printf("1");
    getch();
    }

  2. #2
    Registered User
    Join Date
    Nov 2004
    Location
    USA
    Posts
    516
    i am not having any problem running this program..
    but, you need to make changes...
    1) i dont know how many times this has been told to people, but this is one more time for someone to tell another pal that main returns int and not void
    2) clrscr() is not portable and the same goes with conio.h, so read the faq to clear the screen and to wait for keypress..
    3) dont use getch() ,read the faq as i said earlier
    Code:
    >+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]>++++++++[<++++>-] <.>+++++++++++[<++++++++>-]<-.--------.+++.------.--------.[-]>++++++++[<++++>- ]<+.[-]++++++++++.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > (k=2)
    This is assignment, you mean comparison.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    494
    I think you mean to use this part
    Code:
     i=2;j=1;k=0;
    of your code in a for loop but you are not doing that. here is a tutorial on loops. http://www.cprogramming.com/tutorial/lesson3.html
    When no one helps you out. Call google();

  5. #5
    Registered User Scribbler's Avatar
    Join Date
    Sep 2004
    Location
    Aurora CO
    Posts
    266
    Quote Originally Posted by PING
    2) clrscr() is not portable and the same goes with conio.h, so read the faq to clear the screen and to wait for keypress..
    3) dont use getch() ,read the faq as i said earlier
    There's absolutely nothing in the FAQ that tells you not to use conio.h or compiler specific functions. In fact, this little tidbit can be read in the FAQ concerning the clearing the screen... The best method may be for you to review your compilers documentation, and find a suitable, non-standard function. Which is then followed by an example using conio.h and clrscr(). The FAQ is riddled with examples of compiler specific code.
    Last edited by Scribbler; 03-12-2005 at 12:12 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  5. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM