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
|
int main(void)
{
//creation tableau
struct command *commands = malloc(1*sizeof(struct command));
short nombreCommandes=GetCommandesString("fichier.par",commands);
if(nombreCommandes==-1)
{
exit(EXIT_FAILURE);
}
printf("commands[%d].arg : %s \n", nombreCommandes,commands[nombreCommandes].arg);
}
short GetCommandesString( char * file, struct command *commands)
{
short nombreCommands=-1;
FILE * fp = fopen( file , "r" );
char * aux;
memset(buffer, 0, sizeof(buffer));
while(fgets( buffer , sizeof( buffer ) , fp ))
{
nombreCommands++;
commands = (struct command *)realloc(commands,(nombreCommands+1)*sizeof(struct command));
if(!strncmp( buffer, "arg",3)&&(nombreCommands!=-1))
{
if(strlen(buffer)) buffer[strlen( buffer) - 1 ] = 0;
aux = strchr( buffer , '=' );
aux=trim(aux+1);
strcpy(commands[nombreCommands].arg, aux);
printf("NV ARG de commande: %s \n", commands[nombreCommands].arg);
}
}
fclose( fp );
return nombreCommands;
} |
Partager