-1
I would like to know how to perform two functions at the same time in c Being one while and the other a scanf:
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
#include <locale.h>
#include <windows.h> //para usar o sleep
int main(){
setlocale(LC_ALL, "Portuguese");
char name[10];
int sec=0,chose,monster=64,Fome=10,Higiene=10,Felicidade=10,i=0;
printf("Insira o Nome do Monstrinho.\n");
scanf("%s",name);
system("cls"); // Limpar a tela
while(i<80000){
system("cls");//limpa a tela windows
printf("###########################################\n");
printf("#Nome: %s #\n",name);
printf("#Tempo de Vida : %ds #\n",sec);
printf("#Fome:%d Felicidade;%d Higiene:%d #\n",Fome,Felicidade,Higiene);
printf("# #\n");
printf("# #\n");
printf("###########################################\n");
printf("(1)Comida (2)Carinho (3)Banho (4)...\n");
Sleep(1000); //função sleep
sec++; //segundos
}
It would be before or after the { (key of while), and how can I implement.
printf("Digite uma opção:\n");
scanf("%d",chose); //variavel de escolha de ação
}
Do you really need to do this? Know that in this case you will be working with parallel processing. Within the parallel processing models that exist, I don’t know which one is most suitable for a CLI game (I’m considering your tamagoshi a game, by the way), but I’m biased to a shared variables model (see my answer on CPI).
– Jefferson Quesado
Yeah, you gotta do that
– Raul Lima
Maybe you have a better solution, give more information about what you are doing and why you need it, you are having some problem at the moment?
– Maniero
Good evening, then work and perform a menu that updates with seconds(sec) using the Sleep function, but did not find a way to work also the scanf together.
– Raul Lima