29/12/2011

C Program Without a Main Function

How to write a C program without a main function?. Is it possible to do that. Yes there can be a C program without a main function. Here’s the code of the program without a main function


HERE IS THE CODE

__________________________________________
#include<stdio.h>
#define decode(s,t,u,m,p,e,d) m##s##u##t
#define begin decode(a,n,i,m,a,t,e)

int begin()
{
printf(” hello “);
}

__________________________________________

Does the above program run without the main function? Yes, the above program runs perfectly fine even without a main function. But how, whats the logic behind it? How can we have a C program working without main?


Here we are using preprocessor directive #define with arguments to give an impression that the program runs without main. But in reality it runs with a hidden main function.

The ‘##‘ operator is called the token pasting or token merging operator. That is we can merge two or more characters with it.


NOTE: A Preprocessor is program which processess the source code before compilation.




Look at the 2nd line of program -


#define decode(s,t,u,m,p,e,d) m##s##u##t




What is the preprocessor doing here. The macro decode(s,t,u,m,p,e,d) is being expanded as “msut” (The ## operator merges m,s,u & t into msut). The logic is when you pass (s,t,u,m,p,e,d) as argument it merges the 4th,1st,3rd & the 2nd characters(tokens).


Now look at the third line of the program -


#define begin decode(a,n,i,m,a,t,e)




Here the preprocessor replaces the macro “begin” with the expansion decode(a,n,i,m,a,t,e). According to the macro definition in the previous line the argument must be expanded so that the 4th,1st,3rd & the 2nd characters must be merged. In the argument (a,n,i,m,a,t,e) 4th,1st,3rd & the 2nd characters are ‘m’,'a’,'i’ & ‘n’.

So the third line “int begin” is replaced by “int main” by the preprocessor before the program is passed on for the compiler. That’s it…

The bottom line is there can never exist a C program without a main function. Here we are just playing a gimmick that makes us beleive the program runs without main function, but actually there exists a hidden main function in the program. Here we are using the proprocessor directive to intelligently replace the word begin” by “main”. In simple words int begin=int main.

C PROGRAM TO CLEAR SCREEN WITH OUT USING clrscr() FUCTION



Author Aravinth:

This program is very simple and easy, you all might be thinking how could I do such thing with out using a clrscr(); function. (NOTE: Am talking for turbo c editor as well if this code does not wotrk on other edit please alter it). Lets have the code.



#include<stdio.h>
int main(){
int i,j;
   for(i=0;i<27;i++){
     printf("\n");
     for(j=0;j<80;j++)
       printf(" ");
      }
 gotoxy(1,1);
return 0;
}



Be sure with the code while editing

How to protect USB Pendrives/Flashdrives from VIRUS ?

Lets Protect USB Pendrives / flash drives from Viruses.

Most often our system get infected with virus soon after a USB pendrive has been plugged in. These days it is so easy to get infected by viruses by plugging in a pendrive to your system from unknown source (may be your friends one or your college desktops).

Not all the security programs can defend your pc against the virus attacks carried out through pendrives. But if we can take necessary steps, then we can be safe from such viruses, worms and spywares spreading through pendrives/ flash drives.

So here are some software’s that can efficiently protect your system and pendrive from unknown threats ad viruses.
1.USB Write Protector

It is a software that can help you in write protecting your Pendrive. USB Write Protector allows only to read the data from the pendrive but it wont permit to write data into the pendrive. This is really useful if you take your pendrive to plug on to your friends or relatives pc, as most of the virus enter the pendrive unknowingly. USB Write Protector is a small program, around 190kb in size.


ETY

                     


USB Write Protector

The program doesn’t need any installation and can be directly run from the location. On running the program the window just shows up with just two option to enable write Protection in your Pendrive/ USB Flash Drive and to Turn Off the USB Write Protection. Its that simple. You just need to pick the option and click on OK.
Download
USB writer

2)USB FireWall

As said above, USB write protect software protect your pendrive from viruses, USB firewall likewise protects your PC from viruses. The software protects your system from security threats by launching itself as soon as a USB peripheral is inserted. As soon as USB firewall is launched it works in the background and a window appears when some program tries to launch out automatically since a peripheral USB. USB FireWall is also able to scan all your partitions for auto launched programs and delete the respective autorun file.

USB Firewall is 3.3 MB in size.

Download USB Firewall || Download USB Firewall (Direct Link)

3) Panda USB Vaccination Tool

: It’s a great Tool from Panda that will disable the autorun function from your computer completely and it has a special ability to add a autorun.inf file of its own which can’t be read or deleted or modified. So the autorun virus wont be able to modify it and your system will be safe from the autorun.inf virus even if you plug the pendrive.

You can create a shortcut to the Panda Vaccination Tool with the parameters USBVaccine.exe /resident /hidetray +system and copy the shortcut to the windows startup folder, so that each time a USB device is plugged onto your system, the program popups automatically asking you for vaccination.

Download Panda USB Vaccination Tool

4) USB Guardian

USB Guardian helps you to safely share pictures, movies, documents etc. via your USB pendrive without the risk of being infected by viruses and worms that spread through the pendrives. USB Guardian boasts a clean and simple interface so that so that the user can work with minimum effort.




ETY


USB Guardian

USB Guardian blocks any programs from being automatically executed from a pendrive and thereby it isolates the autorun directives on the removable device.
USB Guardian then scans for any autorun.inf file on the flash drive to check whether it references to any additional files on the pendrive. If any such files are found it automatically blocks those files.

The Locked files will be inaccessible by any other program and you can unlock it using USB Guardian itself if you think the program is harmless. USB guardian is free for use and is 2.96 MB in size.

Download USB Guardian
Hope these tools will help you in protecting and securing your USB Flash drives/ Pendrive from Viruses and Worms.Comments awaited:)

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Best Web Host