lecture d'un tableau uint8_t avec sscanf
Bonjour
j'ai besoin de convertir une chaine de caractere
Code:
1 2
|
char* buffer = "000102030405060708090A0B0C0D0E0F"; |
en un tableau
Code:
1 2 3
|
uint8_t tab[16] = {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9,
0xa, 0xb, 0xc, 0xd, 0xe, 0xf} |
J'ai essaye avec sscanf ca a marche mais ca donne les warnings
Code:
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
|
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#define BUFFER_FORMAT "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
#define MAX_ELEMENTS 16
int main (void)
{
char *buffer = "000102030405060708090A0B0C0D0E0F";
uint8_t tab[MAX_ELEMENTS];
int i;
sscanf(buffer,BUFFER_FORMAT,tab, tab+1, tab+2, tab+3, tab+4,
tab+5 ,tab+6, tab +7, tab +8 , tab +9, tab + 10 , tab + 11,
tab + 12,tab + 13,tab +14, tab + 15);
for ( i=0; i < MAX_ELEMENTS; i++)
{
printf ("tab[%d] = %02x\n", i , tab[i]);
}
return 0 ;
} |
Citation:
gcc -Wall -g sscanf1.c -o sscanf1
sscanf1.c: In function ‘main’:
sscanf1.c:21: warning: format ‘%02x’ expects type ‘unsigned int *’, but argument 3 has type ‘uint8_t *’
sscanf1.c:21: warning: format ‘%02x’ expects type ‘unsigned int *’, but argument 4 has type ‘uint8_t *’
sscanf1.c:21: warning: format ‘%02x’ expects type ‘unsigned int *’, but argument 5 has type ‘uint8_t *’
sscanf1.c:21: warning: format ‘%02x’ expects type ‘unsigned int *’, but argument 6 has type ‘uint8_t *’
sscanf1.c:21: warning: format ‘%02x’ expects type ‘unsigned int *’, but argument 7 has type ‘uint8_t *’
sscanf1.c:21: warning: format ‘%02x’ expects type ‘unsigned int *’, but argument 8 has type ‘uint8_t *’
sscanf1.c:21: warning: format ‘%02x’ expects type ‘unsigned int *’, but argument 9 has type ‘uint8_t *’
sscanf1.c:21: warning: format ‘%02x’ expects type ‘unsigned int *’, but argument 10 has type ‘uint8_t *’
sscanf1.c:21: warning: format ‘%02x’ expects type ‘unsigned int *’, but argument 11 has type ‘uint8_t *’
sscanf1.c:21: warning: format ‘%02x’ expects type ‘unsigned int *’, but argument 12 has type ‘uint8_t *’
sscanf1.c:21: warning: format ‘%02x’ expects type ‘unsigned int *’, but argument 13 has type ‘uint8_t *’
sscanf1.c:21: warning: format ‘%02x’ expects type ‘unsigned int *’, but argument 14 has type ‘uint8_t *’
sscanf1.c:21: warning: format ‘%02x’ expects type ‘unsigned int *’, but argument 15 has type ‘uint8_t *’
sscanf1.c:21: warning: format ‘%02x’ expects type ‘unsigned int *’, but argument 16 has type ‘uint8_t *’
sscanf1.c:21: warning: format ‘%02x’ expects type ‘unsigned int *’, but argument 17 has type ‘uint8_t *’
sscanf1.c:21: warning: format ‘%02x’ expects type ‘unsigned int *’, but argument 18 has type ‘uint8_t *’
Ya t il un moyen d'eliminer ces warnings ?
A l'execution la conversion se fait normalement mais j'ai une erreur
*** stack smashing detected ***: ./sscanf1 terminated
Aborted (core dumped)
Citation:
tab[0] = 00
tab[1] = 01
tab[2] = 02
tab[3] = 03
tab[4] = 04
tab[5] = 05
tab[6] = 06
tab[7] = 07
tab[8] = 08
tab[9] = 09
tab[10] = 0a
tab[11] = 0b
tab[12] = 0c
tab[13] = 0d
tab[14] = 0e
tab[15] = 0f
*** stack smashing detected ***: ./sscanf1 terminated
Aborted (core dumped)