Tutorial on How to have fun with TC in class

Discussion in 'C' started by mayjune, Jul 29, 2009.

  1. mayjune

    mayjune New Member

    Joined:
    Jun 14, 2009
    Messages:
    814
    Likes Received:
    33
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    Pune,Delhi

    Introduction



    A lot of us use TC in our colleges.
    Today I will share with you Two ways to have fun in lab with your teachers. ;)

    Background



    Trick I



    In the first way, you will create an error in any wokring code just by adding one or more numeric letter in it. There will be only one error but on every line. Confused?
    Ok lets begin, to keep things simple I am using a simple code, but you can this method with any code you like.

    Code:
    void hello();
    
    int main()
    {
        printf ("Hi, My name is ");
        hello();
        getch();
    
        return 0;
    }
    
    void hello()
    {
         printf ("Mayjune :)");
    }                                                            [B]//[/B]123
    
    
    As you can see the code is simple and if you have typed it in TC or copied it. Just run it as it is, and it will run.

    Now, to generate error remove the // from //123 and let only 123 be there.
    Goto to any line where you want to generate error in. Run. Volla. You will get an error saying "Declaration Terminated Incorrectly" in a perfectly working code.

    How to fool your teachers?
    Well, Just put that 123 out of visible screen space by putting lot of tabs before it so that when you see the code you cant see 123!! Just goto something like int x; or printf ("Hello"); and run, your teacher will surely get confused, why is this code not working?? :p
    When I had discovered this fault, I thought i'll have some fun, so i generated error and I was like Mam, somethings wrong!! She spent half an hour, looking at my code (it was a huge code) she had no clue whats wrong!! Finally I told her, I was having fun, I found this error in TC. She laughed and went.... :p

    Trick II



    The second Trick is more specific, it will work only on this type of code. The value of a variable will change on its own without using any code!! :p
    Code:
    int main()
      {
       int i,x1[10], y1[10], n;
       clrscr();
       printf ("Enter number of vertices : ");
       scanf ("%d", &n);
       
       acceptpoly(x1,y1);
       
       getch();
       
       return 0;
      }
       
      int acceptpoly(int x1[], int y1[], int n)
      {
        int i;
       
        for (i = 0; i < n; i++)
        {
         printf ("Enter x%d and y%d :");
       
         scanf ("%d %d", x1[i], y1[i]);
        }
        return n;
       
      }
    
    
    The code is fairly simple. Its accepting the number of vertices and then the co-ordinates.
    Ok. Lets Run this program, lets have n = 3. The program will keep asking you enter x and y for 99% of the time greater then 3. Weird Isn’t it.
    Why? Well technically, this program shouldn’t be compiled at the first place. If you notice, while calling acceptpoly() we have sent two parameters but the function is accepting three parameters x, y, n
    If you debug it, after you do first scanf ("%d %d", x1, y1);
    the value of n will change to anything garbage. Before that it will remain to its original value. Its very strange, but then again it shouldn’t happen at all.

    Note –
    1) In Trick 1, do not use characters only use numbers, else error will show only on that line!!!
    2) Trick 2 will not work with void return type. It catches the error, or if you have declared the prototype of the function.
    3) All these tricks work with TC 3.0 It May not work with other versions and most probably won’t work with other compilers.


    These bugs were found by me, I hope you Enjoy it and also You can see how crappy TC is. Quit using TC. Start using ANSI Standard Compliers like
    (*) GCC
    (*) Microsoft VC++ Express (2008 or 2005)
    (*) OpenWatcom C/C++ Compiler
    (*) Digital Mars C/C++ Compiler
    (*) BloodShed DevC++ Compiler
    (*) MinGW32
    (*) DJGPP etc .. (List Compiled By Saswat)

    Thanks :D
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
  3. Raj08

    Raj08 New Member

    Joined:
    Aug 1, 2009
    Messages:
    38
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    Agent 420
    Location:
    India
    hehehe, really nice article for teasing teachers, thanks my dear friend, BUT gone are those days. Missing them a lot.
     
  4. mayjune

    mayjune New Member

    Joined:
    Jun 14, 2009
    Messages:
    814
    Likes Received:
    33
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    Pune,Delhi
    Thanks... it was nice fun when i did this on my teachers :p, you can find your own ways to trouble your boss or someone higher to you ;)
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice