Search This Blog

C Program to Shutdown Computer - How to Shutdown Computer Using C Code

Computer can be shutdown using c program. But the commands are different in Windows and Linux. The system() function in c can be used to execute system commands ( Windows command or Linux command ). To shutdown the computer using c program, we execute the appropriate shutdown command using the system() function.

C Program to Shutdown Windows Computer

The shutdown command in Windows is shutdown. It is executed with command-line argument or option /p for immediate shutdown.

#include<stdio.h>
void main()
{
    system("shutdown /p");
}

C Program to Shutdown Linux Computer

The shutdown command in Windows is shutdown. It is executed with command-line arguments or options -h and now to force immediate shutdown.

#include<stdio.h>
void main()
{
    system("shutdown -h now");
}

No comments: