Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/articles/c-tutorials/)
-   -   Tutorial on How to have fun with TC in class (http://www.go4expert.com/articles/tutorial-fun-tc-class-t18739/)

mayjune 29Jul2009 20:19

Tutorial on How to have fun with TC in class
 

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 :)");
}                                                            //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[i], y1[i]);
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

shabbir 3Aug2009 14:32

Re: Tutorial on How to have fun with TC in class
 
Nominate this article for Article of the month - Jul 2009

Raj08 7Aug2009 18:41

Re: Tutorial on How to have fun with TC in class
 
hehehe, really nice article for teasing teachers, thanks my dear friend, BUT gone are those days. Missing them a lot.

mayjune 7Aug2009 22:08

Re: Tutorial on How to have fun with TC in class
 
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 ;)


All times are GMT +5.5. The time now is 10:14.