#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;
}
嗨!当我回想起主要功能时,我不知道我需要提出什么论点,而且我真的找不到答案,我知道它存在于某个地方。 :)这里是错误,告诉我MinGW编译器。调用带参数的主函数
$ 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
对不起,我的英语不好!谢谢!
C标准原则上禁止调用'main'的程序。 'main'函数应该被定义,但不会被调用.. –
@Basile:这是C++,而不是C(除非在C11中进行了更改)。 – Mat
正如你所看到的,从原型main接受一个int和一个字符串数组(char *),其中int应该是数组的元素个数 – x539