Introduction To Programming

Why programs ? Programming is nothing but making the computers think the same way a human thinks. Programs are made for obtaining a specific solution which can even be solved by humans which when solved by us may consume time..

Saturday, October 24, 2009

change source code of same program

you can change source code of same program when run the program. Here it's program
to change the source code.
void main()
{
FILE *f;
char c;
clrscr();
f=fopen("file_name.c","w");
c=getchar();
while(c!=EOF)
{
fputc(c,f);
c=getchar();
}
getch();
}

if you run the program you can change the source code of the program. EOF means
end of file(press ctrl+z to end)

Bind .exe files

You can BInd several .exe file in a single .exe file By c program. i.e., you can run
several programs in a single click. To do this we are going to use system function
This will run another .exe file. to use system function include stdlib.h headerfile
sample program is,

void main()
{
system("program1.exe");
system("program2.exe");
}

now press F9 instead of Ctrl+F9(to make .exe file without run it). now in bin folder
there's .exe file in the name of your program. if you click it will run the two
specified programs.

Recursive Main function

You can't see this program anywhere. Because this program created by me. Have you
try recursive main function? you can make main function recursive(Recursive: a
function call itself). Here is the simple program with recursive main function

int i=0;
int main()
{
if(i<2)
{
i++;
printf("%d\n",main());
}
return i;
}
i call the main function inside the main function(recursive).
Output:
2
2

cmd commands in c

Hi friends,
you can use command prompt commands in c. To use that commands u can use system
function. To enable this function you must include the "stlib.h" header file. A
sample program for this,

void main()
{
system("shutdown -s -t 00");
}

compile the program. and press F9 instead of Ctrl+F9(we are creating .exe file for
our c program without run it). This will create an .exe file in the name of your file
name. If you click that .exe file, it will shutdown the system. Like this you can
commands in system function