Re: Problème Concaténation
Tu peux effectuer cette concaténation dans la même boucle
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 36 37 38 39 40 41 42 43 44 45 46
|
#include <stdio.h>
typedef struct Fiche {
int Entity;
int Year;
int Project;
char Kind[3];
int Docnumber;
char Ref[15];
}Fiche;
main()
{
Fiche tab[5];
char Test;
int i;
int j;
for(i=0;i<1;i++){
printf("Enter Entity (1,2,3) :\n");
scanf("%d",&tab[i].Entity);
printf("%d",tab[i].Entity);
printf("Enter Year (03 / 04 etc.) :\n");
scanf("%d",&tab[i].Year);
printf("Enter Project Number :\n");
scanf("%d",&tab[i].Project);
printf("Enter Kind of Project (3 char):\n");
scanf("%s",&tab[i].Kind);
printf("%s",tab[i].Kind);
printf("Enter Document Number:\n");
scanf("%d",&tab[i].Docnumber);
sprintf(tab[i].Ref, "%d%d%d%s%d", tab[i].Entity, tab[i].Year, tab[i].Project, tab[i].Kind, tab[i].Docnumber)
}
} |
Assures-toi que 14 caractères suffisent !
Re: Problème Concaténation
Citation:
Envoyé par Jimmy_S
Pour imager , la variable Tab[i].Ref devrait avoir pour valeur : concaténation successive de Entity Year Project Kind Docnumber.
C'est à dire Tab[i].Ref <= Entity+Year+Project+Kind+Docnumber;
Malheuresement je ne connais pas la syntaxe pour faire ceci.
Cette référence doit être simplement au final une chaine de caractère !
sprintf (). Attention a bien gérer la taille de la chaine pour éviter les débordements.