-
Notifications
You must be signed in to change notification settings - Fork 0
/
shutdown.c
45 lines (41 loc) · 939 Bytes
/
shutdown.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void shutdown();
void restart();
int main() {
char choice[20];
label:
printf("Select operation type (restart/shutdown) \n");
scanf("%s", choice);
if (strcmp(choice, "restart") == 0 || strcmp(choice, "Restart") == 0) {
restart();
}
else if (strcmp(choice, "shutdown") == 0 || strcmp(choice, "Shutdown") == 0) {
shutdown();
}
else {
printf("wrong choice please try again \n");
goto label;
}
printf("End of program\n");
return 0;
}
void shutdown(){
#ifdef _WIN32
system("shutdown /s");
#elif __unix__
system("sudo poweroff");
#elif __linux__
system("sudo poweroff");
#endif
}
void restart(){
#ifdef _WIN32
system("shutdown /r");
#elif __unix__
system("sudo reboot");
#elif __linux__
system("sudo reboot");
#endif
}