now this programm is stopped by any key

This commit is contained in:
pierre-geeraert
2016-12-11 22:14:26 +01:00
committed by GitHub
parent eb2a5ab4e2
commit dab90b76fb
+55 -3
View File
@@ -1,6 +1,10 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h>//utile pour la creation d'un nombre aleatoire #include <time.h>//utile pour la creation d'un nombre aleatoire
#include <termios.h>
#include <unistd.h>
#include <fcntl.h>
/*fonction qui permet de creer le random en fonction des resultats precedents*/ /*fonction qui permet de creer le random en fonction des resultats precedents*/
int Random (int _imin, int _imax) int Random (int _imin, int _imax)
@@ -8,6 +12,48 @@
return (_imin + (rand () % (_imax-_imin+1))); return (_imin + (rand () % (_imax-_imin+1)));
} }
/*touche*/
int kbhit(void)
{
struct termios oldt, newt;
int ch;
int oldf;
tcgetattr(STDIN_FILENO, &oldt);
newt = oldt;
newt.c_lflag &= ~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
oldf = fcntl(STDIN_FILENO, F_GETFL, 0);
fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);
ch = getchar();
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
fcntl(STDIN_FILENO, F_SETFL, oldf);
if(ch != EOF)
{
ungetc(ch, stdin);
return 1;
}
return 0;
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
@@ -16,7 +62,7 @@ int main(int argc, char *argv[])
FILE* fichier = NULL; FILE* fichier = NULL;
FILE* history = NULL; FILE* history = NULL;
history = fopen("/media/groupe-tvp/b919f1b0-9122-4865-a76b-bb6386984916/doc/history.txt", "a"); history = fopen("/media/groupe-tvp/b919f1b0-9122-4865-a76b-bb6386984916/doc/history.txt", "a");
fprintf(history," statique\n"); fprintf(history," statique ");
@@ -29,23 +75,28 @@ int main(int argc, char *argv[])
nbrAlea = Random (1,5); nbrAlea = Random (1,5);
fprintf(history," image: ");
/*switch qui permet d'ouvrir une image en fonction d'un nombre aleatoire entre 1 et 5 */ /*switch qui permet d'ouvrir une image en fonction d'un nombre aleatoire entre 1 et 5 */
switch(nbrAlea) switch(nbrAlea)
{case 1: {case 1:
fichier = fopen("image1", "r"); fichier = fopen("image1", "r");
fprintf(history," je suis en pause");
break; break;
case 2: case 2:
fichier = fopen("image2", "r"); fichier = fopen("image2", "r");
fprintf(history," tetris");
break; break;
case 3: case 3:
fichier = fopen("image3", "r"); fichier = fopen("image3", "r");
fprintf(history," start to continue");
break; break;
case 4: case 4:
fichier = fopen("image4", "r"); fichier = fopen("image4", "r");
fprintf(history," psychédélique");
break; break;
case 5: case 5:
fichier = fopen("image5", "r"); fichier = fopen("image5", "r");
fprintf(history," jul");
break; break;
default: default:
break; break;
@@ -100,7 +151,8 @@ break;
} }
//while(1);//attente pour eviter de montrer le prompt while(!kbhit())
printf("");
return 0; return 0;