How to shutdown a PC using C program ?

To shutdown a PC using C, we may use system() function present in the stdlib.h (header file : standard library).

 

CODE :

#include<stdio.h>
#include<stdlib.h>
void main()
{
char choice;

printf(“Press ‘Y’ to Shutdown Your PC : “);
scanf(“%c”,&choice);

 if(choice==’Y’ || choice==’y’)
 {
 system(“C:\WINDOWS\System32\shutdown /s”);   
 }
 else
 {
 printf(“Shutdown Aborted !!!”);
 }
}

NOTE:  use -s instead of /s , if you are using windows XP.

 

 

 

 

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.