Enviado em 14/08/2008 - 09:46h
Alguém sabe como faço pra quando eu apertar uma determinada tecla num console shell(mais exatamente no scanf("%s", spointer) de um programa em C), ae chamar outra função(em outra thread, se preciso) imediatamente, sem interromper a entrada da string?
Aqui o codigo q eu fiz(que não funciona):
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
void *digita(void *vargp);
void *verifica(void *vargp);
int main()
{
pthread_t tid[2];
int n_threads = 2;
pthread_create(tid + 0, NULL, digita, NULL);
pthread_create(tid + 1, NULL, verifica, NULL);
pthread_join(tid[0],(void *) NULL);
pthread_join(tid[1],(void *) NULL);
pthread_exit((void *) NULL);
}
void *digita(void *qq)
{
char file[80];
while (1)
{
fprintf(stdin, "%s", file);
}
pthread_exit((void *) NULL);
}
void *verifica(void *qq)
{
char ch;
while (1) {
fscanf(stdin, "%c", &ch);
if (ch == 9)
fprintf(stderr, "TAB pressionada\n");
/*if (ch == EOF)
rewind(stdin);*/
}
pthread_exit((void *) NULL);
}
Aqui o codigo q eu fiz(que não funciona):
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
void *digita(void *vargp);
void *verifica(void *vargp);
int main()
{
pthread_t tid[2];
int n_threads = 2;
pthread_create(tid + 0, NULL, digita, NULL);
pthread_create(tid + 1, NULL, verifica, NULL);
pthread_join(tid[0],(void *) NULL);
pthread_join(tid[1],(void *) NULL);
pthread_exit((void *) NULL);
}
void *digita(void *qq)
{
char file[80];
while (1)
{
fprintf(stdin, "%s", file);
}
pthread_exit((void *) NULL);
}
void *verifica(void *qq)
{
char ch;
while (1) {
fscanf(stdin, "%c", &ch);
if (ch == 9)
fprintf(stderr, "TAB pressionada\n");
/*if (ch == EOF)
rewind(stdin);*/
}
pthread_exit((void *) NULL);
}