Bonjour à tous,
j'ai écrit une fonction en C qui transforme un tableau de bytes en un string.
Ma fonction marche super bien sous Linux. Maintenant, je suis passé à Windows pour la tester et là ça fait des trucs bizarres, d'après mes tests c'est le sprintf qui foire.
Voyez vous c'est quoi le problème?? car moi ça m'a rendu fou
Merci,
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 #include <stdio.h> #include <string.h> void bytesToString(unsigned char *bytes,int t_bytes,char *string){ int i; char tmp[]="00"; for(i=0;i<t_bytes;i++){ sprintf(tmp,"%02hx",bytes[i]); strcat(string,tmp); } } int main(){ unsigned char bytes[4]={0xf1,0xf2,0xf3,0xf4}; char str[2*4+1]; bytesToString(bytes, 4,str); printf("\n%s\n",str); return 0; }
ilikecz
Partager