"debut TD0"
This commit is contained in:
47
2019-2020/S3T_TP_04_PROCESSUS-3-SGF-2/POPEN_sources/m311_popen_demo.c
Executable file
47
2019-2020/S3T_TP_04_PROCESSUS-3-SGF-2/POPEN_sources/m311_popen_demo.c
Executable file
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
Auteur : RC (inspiration MS)
|
||||
Squelette du programme popen_somme
|
||||
Cf. algorithme dans la fonction main
|
||||
|
||||
NB : La fonction popen() engendre un processus en cr<63>ant un tube
|
||||
(pipe), executant un fork(), et en invoquant le shell avec la
|
||||
commande donn<6E>e dans l'argument no 1.
|
||||
Comme un tube est unidirectionnel par definition,
|
||||
l'argument no 2 doit indiquer seulement une lecture
|
||||
ou une <20>criture, et non pas les deux.
|
||||
Le flux correspondant sera donc ouvert en lecture seule
|
||||
ou <20>criture seule.
|
||||
Cf. man ...
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#define MAX_COMMANDE 100
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
assert (argc == 3);
|
||||
/// Syntaxe : ./a.out <x> <n>
|
||||
/// Exemple : ./a.out 2 10
|
||||
/// Resultat : 2047
|
||||
int x;
|
||||
int n;
|
||||
FILE *fPin;
|
||||
char commande[MAX_COMMANDE];
|
||||
int somme;
|
||||
int l;
|
||||
char unResultat[10];
|
||||
|
||||
/// "n" boucles "for" avec le compteur l
|
||||
{
|
||||
/// Preparation de la commande pour popen(avec sprintf)
|
||||
/// Creation du fils et du pipeline et test d'erreur...
|
||||
/// Avec fscanf, lecture de la valeur x^l produite par ...
|
||||
/// Fermeture avec pclose
|
||||
/// Incrementation de la somme
|
||||
}
|
||||
/// affichage du resultat
|
||||
return 0;
|
||||
}
|
||||
|
17
2019-2020/S3T_TP_04_PROCESSUS-3-SGF-2/POPEN_sources/m311_puiss.c
Executable file
17
2019-2020/S3T_TP_04_PROCESSUS-3-SGF-2/POPEN_sources/m311_puiss.c
Executable file
@@ -0,0 +1,17 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
/// Syntaxe ./argv[0] x n
|
||||
/// Resultat sur stdout : x^n
|
||||
assert (argc == 3);
|
||||
int x = atoi (argv[1]);
|
||||
int n = atoi (argv[2]);
|
||||
|
||||
printf ("%.0f\n",pow (x, n));
|
||||
return 0;
|
||||
}
|
||||
|
22
2019-2020/S3T_TP_04_PROCESSUS-3-SGF-2/POPEN_sources/m311_somme_puiss.c
Executable file
22
2019-2020/S3T_TP_04_PROCESSUS-3-SGF-2/POPEN_sources/m311_somme_puiss.c
Executable file
@@ -0,0 +1,22 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
/// Syntaxe ./argv[0] x n
|
||||
/// Resultat sur stdout : somme x^i avec i entre 0 et n
|
||||
assert (argc == 3);
|
||||
int x = atoi (argv[1]);
|
||||
int n = atoi (argv[2]);
|
||||
int somme = 0;
|
||||
int i;
|
||||
for (i = 0; i<=n ; i++)
|
||||
{
|
||||
somme+=pow(x,i);
|
||||
printf ("... %d\n", somme);/// Mise au point
|
||||
}
|
||||
printf ("%d\n", somme);
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user