Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Erreur étrange sur lecture d'un caractère de argv...

1 réponse
Avatar
Eddahbi Karim
Salut,

Je suis toujours dans mes exercices, je vous poste là juste une
fonction, c'est pas compilable, je sais, mais après avoir lancé le
débugger et valgrind, j'en conclus que l'erreur est ici à la ligne 72.

Je vous poste l'intégrale du fichier (pour que vous puissiez localiser
la ligne 72)

/*-8<-----------------------------------------------------------------

args.c -- Manage the arguments entered by the user.

Author : Eddahbi Karim
E-mail : installation_fault_association at yahoo dot com

----------------------------------------------------------------------

Provides :
- manage_args( char **argv, int argc )

--------------------------------------------------------------------*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

#include "include/voider.h"
#include "include/params.h"
#include "include/options.h"
#include "include/args.h"

/*********************************************************************

NAME : manage_args( char **argv, int argc )

USAGE :
- Manage the arguments entered by the user.

PARAMETERS :
- The arguments entered by the user
- The number of arguments given to the program

RETURNS :
- EXIT_SUCCESS
- EXIT_FAILURE

*********************************************************************/

int manage_args( char **argv, int argc )
{
/* Program status */
int err = EXIT_SUCCESS;

/* The minimal number of arguments */
#ifdef WIPED_NAME
int args_min = 0;
#else
int args_min = 1;
#endif

/* Debug : Check pointers */
assert(argv != NULL);

/* No arguments : stop ! */
if ( argc == args_min )
{
fprintf(stderr, "No arguments given\n");
puts("Insert an argument. See --help for more information");
err = EXIT_FAILURE;
}

/* Treat each argument until there's no more */
else
{
while ( argc != 0 && err == EXIT_SUCCESS )
{

/* First char isn't a '-' : void this argument */
if ( **argv != '-' ) /* <- Le probleme survient ici :-\ */
{
void_string( &*argv );
}

else /* It's a parameter, execute it */
{
err = basic_options( *argv );
}

/* If everything is fine, go to the next argument */
if ( err != EXIT_FAILURE )
{
argv = argv + 1;
argc = argc - 1;
}
}
}

return err;
}

Voilà, je capte pas vraiment.

printf("%c", **argv) fonctionne.
argv = argv + 1;
printf("%c", **argv) aussi.

Pourtant si je refais la même chose sous le débuggueur :
printf "%c", **argv ça m'indique 0x0...

void_string se résume à ça :

void
void_string( char **const string )
{
/* The position in the string */
unsigned int i = 0;

/* Debug : Check the pointer */
assert( string != NULL );

(void) printf("Voiding %s...\n", *string);

/* Initialize each element to 0 */
for( i = 0; i < FIRST_DIM_SIZE(*string); i++ )
{
string[i] = 0;
}

(void) printf("Voided %s\n", *string);

}

(Le dernier printf sera enlevé une fois que le programme sera fini. Pour
l'instant il me permet de détecter d'éventuels bugs).

Voilà,
Si vous avez une idée

--
--
ThE_TemPLaR

1 réponse

Avatar
AG
tu peux nous montrer ce que tu mets dans argv ? Comment tu le déclares
etc...

Eddahbi Karim wrote:
Salut,

Je suis toujours dans mes exercices, je vous poste là juste une
fonction, c'est pas compilable, je sais, mais après avoir lancé le
débugger et valgrind, j'en conclus que l'erreur est ici à la ligne 72.

Je vous poste l'intégrale du fichier (pour que vous puissiez localiser
la ligne 72)

/*-8<-----------------------------------------------------------------

args.c -- Manage the arguments entered by the user.

Author : Eddahbi Karim
E-mail : installation_fault_association at yahoo dot com

----------------------------------------------------------------------

Provides :
- manage_args( char **argv, int argc )

--------------------------------------------------------------------*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

#include "include/voider.h"
#include "include/params.h"
#include "include/options.h"
#include "include/args.h"

/*********************************************************************

NAME : manage_args( char **argv, int argc )

USAGE :
- Manage the arguments entered by the user.

PARAMETERS :
- The arguments entered by the user
- The number of arguments given to the program

RETURNS :
- EXIT_SUCCESS
- EXIT_FAILURE

*********************************************************************/

int manage_args( char **argv, int argc )
{
/* Program status */
int err = EXIT_SUCCESS;

/* The minimal number of arguments */
#ifdef WIPED_NAME
int args_min = 0;
#else
int args_min = 1;
#endif

/* Debug : Check pointers */
assert(argv != NULL);

/* No arguments : stop ! */
if ( argc == args_min )
{
fprintf(stderr, "No arguments givenn");
puts("Insert an argument. See --help for more information");
err = EXIT_FAILURE;
}

/* Treat each argument until there's no more */
else
{
while ( argc != 0 && err == EXIT_SUCCESS )
{

/* First char isn't a '-' : void this argument */
if ( **argv != '-' ) /* <- Le probleme survient ici :- */
{
void_string( &*argv );
}

else /* It's a parameter, execute it */
{
err = basic_options( *argv );
}

/* If everything is fine, go to the next argument */
if ( err != EXIT_FAILURE )
{
argv = argv + 1;
argc = argc - 1;
}
}
}

return err;
}

Voilà, je capte pas vraiment.

printf("%c", **argv) fonctionne.
argv = argv + 1;
printf("%c", **argv) aussi.

Pourtant si je refais la même chose sous le débuggueur :
printf "%c", **argv ça m'indique 0x0...

void_string se résume à ça :

void
void_string( char **const string )
{
/* The position in the string */
unsigned int i = 0;

/* Debug : Check the pointer */
assert( string != NULL );

(void) printf("Voiding %s...n", *string);

/* Initialize each element to 0 */
for( i = 0; i < FIRST_DIM_SIZE(*string); i++ )
{
string[i] = 0;
}

(void) printf("Voided %sn", *string);

}

(Le dernier printf sera enlevé une fois que le programme sera fini. Pour
l'instant il me permet de détecter d'éventuels bugs).

Voilà,
Si vous avez une idée