C program to shutdown and restart your computer - The Idle Coder

C program to shutdown and restart your computer

Hi guys.. I m here to share one superb program about how to shutdown and how to restart your computer with the help of c program. I know ,you are thinking that it will have long source code. Then you are wrong!! It is so simple like writing a program about
hello world.
Lets see the below source code for shutdown your computer using c program.


Also read: Ternary operator in java

How to shutdown your computer by c program

Here is the code to perform it.

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
int main()
{
               char st;
          clrscr();
          printf(" Are you sure to shutdown your computer. Please mention(y/n)");
          scanf("%c",&st);

          if(st=='y' || st=='Y')
              {
           system("c:\\windows\\system32\\shutdown /s");
           system("pause");
          }
 return(0);
}

Logic of the above program is so simple. First we have included standard library file and defined one variable having character type. The system command will open the particular path to shutdown your computer.

How to restart your computer  by c program.


Here is the code of it.

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
int main()
{
                    char st;
             clrscr();
             printf("Are you sure to restart your computer?.Please mention it(y/n):");
             scanf("%c",&st);

             if(ch=='y' || ch=='Y')
            {
                 system("c:\\windows\\system32\\shutdown /r");
                 system("pause");
             }
           return(0);
}

Logic of above program is same as we mentioned for first program. Firstly it include library file and then open the path of restart command to perform desired operation in c program.


Also read:  List of turbo c++ commands

Important note
It will be little tricky in turbo c compiler. If you are using turbo c then you just need to compile your program with help of ALT+F9. You doesn't need to run it directly from inside the turbo c. You have to go in particular drive and open exe file of the program. That’s it!

So it is a good practice to execute this type of programs. Tell me about your experience of this program in comment box. If you need any help then don’t be shy.Just ask me!


Previous
Next Post »