我正在使用WinCE7.I需要在t1
之类的变量中存储特定输入高的时间值。然后,如果输入再次为高,则将时间值存储在另一个变量t2
中。如何在c。
现在我在t1节省时间,如下所示:
sprintf(time," %d:%d:%d:%d\n",systemTime.wHour,systemTime.wMinute,systemTime.wSecond,systemTime.wMilliseconds);
if(input==high)
{
strcpy(t1,time);
printf("time %s\n",t1);
}
答案 0 :(得分:1)
你可以使用数组存储多次等。下面是一种伪代码。根据您的实际代码进行更改。
char t1[30][20], time[20];
int counter = 0 , low=0;
while(counter < 30) {
sprintf(time," %d:%d:%d:%d\n",systemTime.wHour,systemTime.wMinute,systemTime.wSecond,systemTime.wMilliseconds);
if(input==high)
{
strcpy(t1[counter],time);
printf("time %s\n",t1[counter]);
//reset the input or whatever
input = low;
counter++; // change index
}
}
答案 1 :(得分:0)
使用整数值i = 0
计算输入高的次数。例如:
i = 0;
if(input==high)
{
i++;
if(i==1) //Input is high for the first time
{
strcpy(t1,time);
printf("time %s\n",t1);
}
if(i==2) //Input is high for the second time
{
strcpy(t2,time);
printf("time %s\n",t2);
}
if(i==3) //Input is high for the third time
{
strcpy(t3,time);
printf("time %s\n",t3);
}
//same for other
}