os2 a écrit a écrit :
tu peux afficher ton script ici
|
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define SIZETAB 6
#define MAXCHAR 100
char *tables[SIZETAB];
char input_f[30];
char output_f[30];
char *cmdd;
char *cmdf;
char *command;
void launch_bat();
void help(void);
void writefile(char *mot);
char *insert(char *table);
void read(char *fichier)
{
FILE *fic;
FILE *sortie;
char temp[32];
char *cmd;
int j;
int i=0;
fic = fopen(fichier,"r" );
if(fic != NULL)
{
do
{
fscanf(fic, "%s", temp);
tables[i]=malloc(strlen(temp)*sizeof(char));
strcpy(tables[i],temp);
i++;
}
while(!feof(fic));
//Pour se situer reelement a la derniere ligne
i--;
fclose(fic);
sortie = fopen("greptables.bat","a" );
if(sortie != NULL)
{
for(j=0;j<i;j++)
{
cmd = malloc(50*sizeof(char));
strcpy(cmd,insert(tables[j]));
fputs(cmd, sortie);
free(tables[j]);
free(cmdf);
free(cmdd);
free(command);
}
fclose(sortie);
}
launch_bat();
}
else printf("le fichier %s n'a pas pu etre ouvert",input_f);
}
void launch_bat(void)
{
system("greptables.bat" );
}
char *insert(char *table)
{
char *cmd;
char *separateur = "/";
int dbt;
int fin;
int var;
command=malloc(50*sizeof(char));
strcpy(command,"grep -i -l -c -d / *.* >> ResultatGrep.txt\n" );
cmdd = strtok(command,separateur);
cmdf = strtok(NULL,"" );
dbt = strlen(cmdd);
fin = strlen(cmdf);
var = strlen(table)+1;
cmd=malloc((var+fin+dbt)*sizeof(char));
sprintf(cmd,"%s%s%s",cmdd,table,cmdf);
return(cmd);
}
void help(void)
{
printf("Correct syntax is :\n list <input.file> <output.file>" );
}
void main(int argc, char *argv[])
{
//argc = 3;
//argv[1]="liste.txt";
//argv[2]="result.txt";
if (argc != 3) help();
else
{
strcpy(input_f,argv[1]);
strcpy(output_f,argv[2]);
read(input_f);
}
}