Petit souci avec sprintf() en C
Résolu
balou311
Messages postés
766
Statut
Membre
-
walha -
walha -
Salut tout le monde,
alors voila j'ai un souci car j'ai un prog ou un certain sprintf fonctionne mais pas le suivant
un peu d'aide sera la bienvenue je comprend pas du tout pourquoi ça plante
#include <stdio.h>
#include <string.h>
#include perso.h
#include<stdlib.h>
char * page_xml_haut = "<nom_op>%s\n"
"\t<employe></employe>\n"
"\t<machine>%s<machine>\n"
"\t<date_debut>%s</date_debut>\n"
"\t<heure_debut>%s</heure_debut>\n"
"\t<date_fin>%s</date_fin>\n"
"\t<heure_fin>%s</date_fin>\n";
char * page_xml_qt = "\t<matiere_%d>%s\n"
"\t\t<qt_conso>%d</qt_conso>\n"
"\t</matiere_%d>\n";
char * page_xml_bas = "</nom_op>\n";
int modif_qt_mat ( struct w_zone * p_w_zone, int argc, char * argv[])
{
struct operation *l_op;
struct matiere *l_matiere;
char * b_page_xml;
char * b_tmp;
int b_nb_mat;
int b_compt = 0;
l_matiere = p_w_zone->p_matiere;
b_nb_mat = p_w_zone->p_wof.qt_matiere;
l_op = p_w_zone->p_op;
sprintf(b_page_xml, page_xml_haut, l_op->nom, l_op->machine, l_op->date_debut, l_op->h_debut, l_op->date_fin, l_op->h_fin);
while (b_nb_mat > b_compt)
{
printf("nb_mat : %d",b_nb_mat);
sprintf(b_tmp,page_xml_qt,b_compt,l_matiere->code,l_matiere->qte_consommee,b_compt);
strcat(b_page_xml,b_tmp);
l_matiere ++;
b_compt ++;
}
strcat(b_page_xml,page_xml_bas);
printf(b_page_xml);
}
C'est donc un prog principale qui appele ce sous prog mais quedal c'est ce qui est souligné qui plan,te je comprend pas pourquoi please help
sinon j'ai vérifier les paramètres sont bien passés et les structures sont bonnes
merci d'avance pour votre aide
alors voila j'ai un souci car j'ai un prog ou un certain sprintf fonctionne mais pas le suivant
un peu d'aide sera la bienvenue je comprend pas du tout pourquoi ça plante
#include <stdio.h>
#include <string.h>
#include perso.h
#include<stdlib.h>
char * page_xml_haut = "<nom_op>%s\n"
"\t<employe></employe>\n"
"\t<machine>%s<machine>\n"
"\t<date_debut>%s</date_debut>\n"
"\t<heure_debut>%s</heure_debut>\n"
"\t<date_fin>%s</date_fin>\n"
"\t<heure_fin>%s</date_fin>\n";
char * page_xml_qt = "\t<matiere_%d>%s\n"
"\t\t<qt_conso>%d</qt_conso>\n"
"\t</matiere_%d>\n";
char * page_xml_bas = "</nom_op>\n";
int modif_qt_mat ( struct w_zone * p_w_zone, int argc, char * argv[])
{
struct operation *l_op;
struct matiere *l_matiere;
char * b_page_xml;
char * b_tmp;
int b_nb_mat;
int b_compt = 0;
l_matiere = p_w_zone->p_matiere;
b_nb_mat = p_w_zone->p_wof.qt_matiere;
l_op = p_w_zone->p_op;
sprintf(b_page_xml, page_xml_haut, l_op->nom, l_op->machine, l_op->date_debut, l_op->h_debut, l_op->date_fin, l_op->h_fin);
while (b_nb_mat > b_compt)
{
printf("nb_mat : %d",b_nb_mat);
sprintf(b_tmp,page_xml_qt,b_compt,l_matiere->code,l_matiere->qte_consommee,b_compt);
strcat(b_page_xml,b_tmp);
l_matiere ++;
b_compt ++;
}
strcat(b_page_xml,page_xml_bas);
printf(b_page_xml);
}
C'est donc un prog principale qui appele ce sous prog mais quedal c'est ce qui est souligné qui plan,te je comprend pas pourquoi please help
sinon j'ai vérifier les paramètres sont bien passés et les structures sont bonnes
merci d'avance pour votre aide
A voir également:
- Petit souci avec sprintf() en C
- Petit 2 ✓ - Forum Bureautique
- Comment écrire mètre carré avec un m+2 expos? ✓ - Forum Windows
- Comment imprimer une photo en petit - Forum Photo numérique
- Petit point vert snap ✓ - Forum Snapchat
- Trier du plus petit au plus grand excel - Guide
1 réponse
T'es sur que l_matiere->code est bien défini en char * et qu'une valeur lui a été affectée (en gros que tous les éléments de la structure p_w_zone->p_matiere ont été valorisés) ?
Je ne vois que deux erreurs possibles:
1) l_matiere->code n'est pas défini en char * ou l_matiere->qte_consommee n'est pas défini en int.
2)Tu n'as pas alloué de mémoire pour p_w_zone->p_matiere.code.
A+
Je ne vois que deux erreurs possibles:
1) l_matiere->code n'est pas défini en char * ou l_matiere->qte_consommee n'est pas défini en int.
2)Tu n'as pas alloué de mémoire pour p_w_zone->p_matiere.code.
A+
avec un jonglage d'adresse mémoire
A+