Posted in

How To shutdown Your Computer using C Program

Shutdown Your Computer with Coding 

[ C Programming ]


In this article, we will discuss how to shut down your Pc or laptop with C programing language.C programming language is easy to learn, and everyone should code easily.
1.Linux/Ubuntu
  • To follow the code will shut down your PC running either in Ubuntu Operating System or Linux Operation System.
  • To shut down your PC (for Linux clients), you should be signed in as root client for the above program to execute, else you will get the message shutdown.
Program
       #include <stdio.h> 
       #include <stdlib.h> 
       {
            system(“shutdown -P now”); 
            return 0; 
        }

Explanation:


shutdown: Presently indicates that you need to shut down immediately.
-P: Represent indicates that you need to power off your machine or computer.
You can determine minutes as shutdown – P “number of minutes”
2.Windows
  • To follow the code will shutdown your Pc running on Windows operating system.
  • To shut down your computer using the C program, You’ll need to call the system() function which will call the cmd.
  • stdlib.h contain the system() function and it is used to run any executable file. 
Program
#include<stdio.h>
#include<conio.h>
 #include<stdlib.h> 
void main() 
{  
char c;  
printf(“Do you want to shutdown your PC/Computer (y/n) : “);  
scanf(“%c”,&c);  
if(c==’y’ || c==’Y’)
system(“C:\Windows\System32\shutdown /s /t 0”); 
else
printf(“You don’t wanna shut down your PC/Computer”);
getch();
}

Explanation


/s: It represents shutdown.
/t: represents Time means after how much time you want to shut down your computer. If you will not define the time /t, It will take default time 30 sec after shut down your pc.
Note: Save the file with .c extension. 

I am a Software Engineer with a strong interest in writing technology-related articles, managing two websites. I am dedicated to learning new technologies and producing engaging content. Additionally, I possess expertise in digital marketing and SEO strategies.

Leave a Reply

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