在c程序 中怎么设置shutdown 里的时间参数 ?

来源:百度知道 编辑:UC知道 时间:2024/06/20 11:28:34
system("Shutdown.exe -s -t 1000" );
把1000改成一个变量?

这么写:
int a=1000;
system(string.Format("shutdown -s -t %d",a));

或者:
char szCmd[30];
int a=1000;
sprintf(szCmd,"shutdown -s -t %d",a);

system(szCmd);

#include<stdio.h>
#include <stdlib.h>
main()
{
int ntime=1000;
char szStr[100]="Shutdown.exe -s -t ";
char szTime[5];
itoa(ntime,szTime,10);
strcat(szStr,szTime);
printf("%s",szStr);

system(szStr);
}