[pointeurs][tableaux]copier un tableau dans un indice de tab
Bonjour,
j'ai une chaine de caractere dans un tableau:
liste[15]={11,12,13,14,15}
je voudrais avoir ceci:
tab[0]="11";
tab[1]="12";
...
mais je n'y arrive pas;
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
for (k=0;k<strlen(h_liste_uc) || h_liste_uc[k]!='\0';k++)
{
if (h_liste_uc[k]==',')
{
uc[e++]='\0';
Trace(9,"uc: [%s]",uc);
tabUc[b]=uc;
b++;
Trace(9,"tabUc: [%s]",tabUc[0]);
Trace(9,"tabUc: [%s]",tabUc[1]);
Trace(9,"tabUc: [%s]",tabUc[2]);
e=0;
/*memset(uc,NULL,sizeof(uc));*/
}
else
{
uc[e++]=h_liste_uc[k];
}
} |
j'obtiens ceci;
# 13/01/2006 13:51:08 # uc: [00031]
# 13/01/2006 13:51:08 # tabUc: [00031]
# 13/01/2006 13:51:08 # tabUc: [(null)]
# 13/01/2006 13:51:08 # tabUc: [(null)]
# 13/01/2006 13:51:08 # uc: [10046]
# 13/01/2006 13:51:08 # tabUc: [10046]
# 13/01/2006 13:51:08 # tabUc: [10046]
# 13/01/2006 13:51:08 # tabUc: [(null)]
# 13/01/2006 13:51:08 # uc: [10300]
# 13/01/2006 13:51:08 # tabUc: [10300]
# 13/01/2006 13:51:08 # tabUc: [10300]
# 13/01/2006 13:51:08 # tabUc: [10300]
Merci de votre aide
Re: [pointeurs][tableaux]copier un tableau dans un indice de
Citation:
Envoyé par zozolh2
j'ai une chaine de caractere dans un tableau:
liste[15]={11,12,13,14,15}
??? Même en admettant que liste est de type char, 11,12 sont peut être des caractères (lequels, ça dépend du charset), mais il n'y a pas de 0 final. Ce n'est donc pas une chaine.
Citation:
je voudrais avoir ceci:
tab[0]="11";
tab[1]="12";
si les éléments de tab sont des char* ou des tableaux de char, c'est possible...
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 33 34 35
|
Compiling: main.c
main.c:1: error: syntax error before "for"
main.c:6: error: syntax error before numeric constant
main.c:6: warning: type defaults to `int' in declaration of `Trace'
main.c:6: warning: function declaration isn't a prototype
main.c:6: warning: data definition has no type or storage class
main.c:7: error: `b' undeclared here (not in a function)
main.c:7: warning: type defaults to `int' in declaration of `tabUc'
main.c:7: error: `uc' undeclared here (not in a function)
main.c:7: warning: data definition has no type or storage class
main.c:8: error: syntax error before '++' token
main.c:9: error: syntax error before numeric constant
main.c:9: warning: type defaults to `int' in declaration of `Trace'
main.c:9: warning: function declaration isn't a prototype
main.c:9: warning: redundant redeclaration of 'Trace'
main.c:6: warning: previous declaration of 'Trace' was here
main.c:9: warning: data definition has no type or storage class
main.c:10: error: syntax error before numeric constant
main.c:10: warning: type defaults to `int' in declaration of `Trace'
main.c:10: warning: function declaration isn't a prototype
main.c:10: warning: redundant redeclaration of 'Trace'
main.c:9: warning: previous declaration of 'Trace' was here
main.c:10: warning: data definition has no type or storage class
main.c:11: error: syntax error before numeric constant
main.c:11: warning: type defaults to `int' in declaration of `Trace'
main.c:11: warning: function declaration isn't a prototype
main.c:11: warning: redundant redeclaration of 'Trace'
main.c:10: warning: previous declaration of 'Trace' was here
main.c:11: warning: data definition has no type or storage class
main.c:12: warning: type defaults to `int' in declaration of `e'
main.c:12: warning: data definition has no type or storage class
main.c:14: error: syntax error before '}' token
main.c:7: error: storage size of `tabUc' isn't known
Process terminated with status 1 (0 minutes, 1 seconds) |
Ce code n'est pas compilable. Pour le rendre compilable, ilf aut des tas d'hypothèses probablement différentes de ta réalité, donc sans signification réelle. Il faut poster un code complet, compilable (si possible) et réduit au minimum, qui montre le défaut.
Citation:
j'obtiens ceci;
Et moi, je n'obtiens rien du tout.