1
I am making a code that rotates a clock to show when the time of use of a machine (informed by the user). In the code the clock is inside a while(1), so there is no way for the user to inform the time of use of the machine.
the code of the clock is this:
while (1 == 1) {
Sleep (100);
segundos++;
system("cls");
if (segundos > 59) { minutos++; segundos = 0; }
if (minutos > 59) { horas++; minutos = 0; }
if (horas > 23) { dias++; horas = 0; }
if (mes > 30) { mes++; dias = 0; }
printf("%d: %d: %d %d %d", mes, dias, horas, minutos, segundos);
}
And the code to be informed the time is this:
printf("Digite 1 para maquinas, 2 para pessoas, 3 para estoque, 4 para horarios, 5 para alterar o nome do laboratorio e 6 para finalizar.\n");
scanf("%d", &y);
system("cls");
if(y == 1){
printf("Vamo comecar o cadastro das maquinas.\n");
printf("Quantas maquinas deseja cadastrar?\n");
scanf("%d", &z);
for(i=0; i<z; i++){
fflush(stdin);
printf("Qual o nome da maquina %d?\n", i+1);
gets(m[c].maquina);
printf("Qual o tempo de vida util da maquina?\n");
printf("Expresse o tempo em meses.\n");
scanf("%d", &m[c].tempo);
fflush(stdin);
c++;
}
system("cls");
printf("Muito bem, o cadastramento das maquinas foi um sucesso!\n");
printf("O programa avisa automaticamente quando o tempo de vida util da maquina expirar.\n");
}
printf("Informacoes do cadastro de maquinas:\n\n");
for(i=0; i<c; i++){
printf("CADASTRO DA MAQUINA %d\n", i+1);
printf("O nome da maquina eh %s\n", m[i].maquina);
printf("A vida util da maquina eh de %d meses\n", m[i].tempo);
if(m[i].maquina == mes){
printf("A maquina necessita de manuntençao.\n");
}
printf("\n");
}
I wonder if you have another way to create a clock or if you have a way to make that clock run in the code background.
The problem of
time()
is that the AP wants a method that "... does not [have] how the user informs the time of use of the machine", and user can delay maintenance indefinitely by changing Windows clock if you usetime()
.– Wtrmute
I have a question, from what I understand the team only takes the time of the system, has to get the date of the system ? Since in the case of my program it would take years, months and not just hours.
– Gabriel Leite
It would be necessary to be able to manipulate this date also, comparing with integers, that is, it would have to be informed in integers.
– Gabriel Leite
wrmute in this case there would be a good take time from an external server by socket, bad would be if person pull the cable from the net then program does not work kkk, use the Gettickcount api would be an alternative too.
– kodo no kami
Gabriel the team takes the day, week, month and year too. for the day in the month Voce uses tm_mday, the day in the year tm_yday, the month use tm_mon (starts at 0), the year use tm_year (return 117 = 2017)
– kodo no kami
@kodonokami:
time()
returnstime_t
, which is the number of seconds elapsed since January 1, 1970, GMT. to return astruct tm
(withtm_yday
etc) have to saylocaltime(time(NULL))
orgmtime(time(NULL))
to make the conversion (the first is in the local time zone, the second in UTC).– Wtrmute