Reputation: 1435
#include <string.h>
#include <stdio.h>
#include <windows.h>
#include <wchar.h>
#include <unistd.h>
#define sleep(x) Sleep(1000 * x)
int checkTime();
int main ( int argc, char *argv[] ) {
char *getFirstArgument = argv[1];
char *getSecondArgument = argv[2];
char getCheckTime;
checkTime(&getCheckTime);
if(*getFirstArgument != getCheckTime) {
sleep(1);
main(*getFirstArgument);
} else if(*getFirstArgument == getCheckTime && *getSecondArgument == 'r') {
system("shutdown /r");
} else if(*getFirstArgument == getCheckTime) {
system("shutdown /s");
}
return 0;
}
int checkTime() {
char getConvertedTime[5] = {};
SYSTEMTIME localTime;
GetLocalTime ( &localTime );
sprintf( getConvertedTime, "%d:%d", localTime.wHour, localTime.wMinute );
printf( "%s\n", getConvertedTime );
return 0;
}
Hi! I don't know what arguments I need to put when I recall main function, and I really can't find the answer, I know it's exist somewhere. :) And here is the error what show me the MinGW compiler.
$ gcc -Wall test.c -o test.exe
test.c: in function 'main':
test.c:20:3: error: to few arguments to function 'main'
test.c:10:5: note: declared here
Sorry for my bad english! Thank you!
Upvotes: 0
Views: 4441
Reputation: 37915
Instead of calling main()
after 1 second to create some sort of loop to wait for a specified amount of time, you can use an actual loop! Try something like this:
checkTime(&getCheckTime);
while(*getFirstArgument != getCheckTime) {
sleep(1);
checkTime(&getCheckTime);
}
// Do something after the provided time
if(*getSecondArgument == 'r') {
system("shutdown /r");
} else {
system("shutdown /s");
}
Furthermore, I do not really understand what you are planning to do. So the snippet above will not likely fix your complete program.
Upvotes: 2