1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# define LNG_MAX 20
# define LAR_MAX 20
# define ATTOUL 1000
# define SEP ""
///
static void clean (char *chaine) ;
////
int main ( int argc , char* argv[] )
{
int i = 0 ;
int j = 0 ;
FILE* flot = NULL ;
int tab[LNG_MAX][LAR_MAX] ;
char put_here [ATTOUL] = "";
char* token = NULL ;
/** initialisation du tableau **/
for ( i =0 ; i< LNG_MAX ; i++)
{
for ( j =0 ; j< LAR_MAX ; j++)
{
tab[i][j] = 0 ;
}
}
/** reinitialisation des variables i et j a cause de lincremantation **/
i = 0 ;
j = 0 ;
/** recuperation des données a partir du fichier unix **/
flot = popen (" grep toto1 /var/sum ", " r ") ;
flot = popen (" grep toto2 /var/sum ", " r ") ;
flot = popen (" grep toto3 /var/sum ", " r ") ;
/** verification de ladresse retourné par popen**/
if ( flot == NULL )
{
printf (" echec process ") ;
break ;
}
/** lecture du flot ligne par ligne **/
while ( !feof (flot) && i< LNG_MAX )
{
/** je recupere chaque ligne pour la stocker dans le tableau chaine **/
fgets ( put_here,sizeof(put_here),flot);
/** je supprime le "\n" et vide mon stdin **/
clean ( put_here);
/** je decoupe ma ligne selon le caractere espace " " **/
token = strtok (put_here,SEP);
/** convertion en entier &Implementation du tableau**/
while ( token!=NULL && j< LAR_MAX )
{
tab[i][j] = atoi(token);
j++;
}
i++ ;
pclose(flot);
}
return 0 ;
}
/*************** fonction clean************/
static void purger(void)
{
int c;
while ((c = getchar()) != '\n' && c != EOF)
{}
}
static void clean (char *chaine)
{
char *p = strchr(chaine, '\n');
int c;
if (p)
{
*p = 0;
}
else
{
purger();
}
}
|
Partager