C/C++ program to shutdown a system

Configurare noua (How To)

Situatie

How to shutdown your computer in Linux and/or Windows?

The idea is to use system() in C. This function is used to invoke operating system commands from C program.

Solutie

Pasi de urmat

Linux OS:

// C program to shutdown in Linux
#include <stdio.h>
#include <stdlib.h>
 
int main()
{
   // Running Linux OS command using system
   system("shutdown -P now");
   
   return 0;
}

Windows OS:

We will make use of system() from < stdlib.h > to perform a system operation with the help of a C program.To perform any of the afore-mentioned system operation we will code as:

#include <stdio.h>
#include <stdlib.h>
 
int main()
{
  system("c:\\windows\\system32\\shutdown /i");
  return 0;
}

Tip solutie

Permanent

Voteaza

(6 din 13 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?