begin process at 2010 03 14 08:39:51
  Trouver un code source :
 
dans
 
Accueil > Forum > 

C

 > 

Windows

 > 

Fichier & Disque

 > 

Le programme plante à la fin


Derniers messages déposésPoser une question dans le forum ou lancer une discussion

Le programme plante à la fin

mardi 28 août 2007 à 11:07:43 | Le programme plante à la fin

deguelator

Bonjour à tous. J'ai posté ce messange en espérant que vous puissiez m'aider sur un problème que je n'arrive pas à résourdre.
Le programme permet de creer des pages HTML. J'utilise la bibliothèque Malloc (avec gets) pour récuperer les données nécéssaires. Le programme fonctionne correctement mais en sortie de boucle FOR, le programme plante. Le code en bleu vous pouvez laisser tomber. Le code qui me semble fautif est souligné à la fin.

MERCI.





#include <stdio.h>
#include <conio.h>
#include <malloc.h>
#include <string.h>

int main()
{
        /*
   Déclaration de l'ensemble des variables
   */
  
   char *nom_de_la_page, *titre_de_la_page, *localisation, *description, *image, *image2, *image3, *description_detaillee ,    *en_savoir_plus;
   char *commentaire1, *commentaire2, *commentaire3;
   int prix, reference, surface_terrain, surface_habitable, nombre_de_produit , nombre_reference;
  
   nom_de_la_page = (char *)malloc(15);
   titre_de_la_page = (char *)malloc(15);
   localisation = (char *)malloc(15);
   description = (char *)malloc(25);
   image = (char *)malloc(15);
   description_detaillee = (char *)malloc(200);
   en_savoir_plus = (char *)malloc(15);
   image2 = (char *)malloc(15);
   image3 = (char *)malloc(15);
   commentaire1 = (char *)malloc(15);
   commentaire2 = (char *)malloc(15);
   commentaire3 = (char *)malloc(15);
  
   nombre_reference = 0;
  
  
 
   /*
   Debut du traitement
   */
  
   puts("\nCombien de produits desirez-vous ajouter?");
   scanf("%d",&nombre_de_produit);
  
   fflush(stdin);
  
  
   puts("\nSaisir le nom de la page:");
   gets(nom_de_la_page);
  
   puts("\nSaisir le titre de la page:");
   gets(titre_de_la_page);
  
  
   /*Creation du listing*/
   printf("\n\tCreation de la page %s",nom_de_la_page);
                                        
   char filename[255];
             
   FILE *fichier;
   sprintf((char *) &filename,"%s.html",nom_de_la_page);
   fichier = fopen(filename,"w");
                                                
   if(fichier == NULL)
   {
              puts("\n\t\t---->LA PAGE HTML N'A PU ETRE CREE");
              fclose(fichier);
   }
                                                
   else
   {
              puts("\n\t\t---->CREATION DE LA PAGE HTML REUSSIE");
   }
                                        
 
  
   for(nombre_reference = 0;nombre_reference < nombre_de_produit;nombre_reference++)
   {
                                        
                                         /*Saisie des variables de type caractère*/
                                        
                                         puts("\nSaisir la localisation du produit:");
                                         gets(localisation);
                                        
                                         puts("\nSaisir une description succinte du produit:");
                                         gets(description);
                                        
                                         puts("\nSaisir le nom de l'image a afficher en indiquant son format:");
                                         gets(image);
                                        
                                         puts("\nSaisir la description detaillee du produit:");
                                         gets(description_detaillee);
                                        
                                         puts("\nSaisir le nom de la page 'en savoir plus'");
                                         gets(en_savoir_plus);
                                        
                                         puts("\nDonnez les noms de image2 et 3 puis des comm:");
                                         gets(image2);
                                         gets(image3);
                                         gets(commentaire1);
                                         gets(commentaire2);
                                         gets(commentaire3);
                                        
                                        
                                         /*Saisie des variables de type entiers*/
                                         puts("\nSaisir la surface habitable");
                                         scanf("%d",&surface_habitable);
                                        
                                         puts("\nSaisir la surface du terrain:");
                                         scanf("%d",&surface_terrain);
                                        
                                         puts("\nSaisir la reference du produit:");
                                         scanf("%d",&reference);
                                        
                                         puts("\nSaisir le prix:");
                                         scanf("%d",&prix);
                                        
                                        
                                                  /*
                                                     Ecriture dans le listing
                                                  */
      
       fprintf(fichier,"<HTML>\n<HEAD>\n<TITLE>%s</TITLE>\n</HEAD>",nom_de_la_page);
       fprintf(fichier,"\n<BODY bgcolor='#9933FF' TOPMARGIN='50' BOTTOMMARGIN='50' LEFTMARGIN='60' RIGHTMARGIN='60'>");
       fprintf(fichier,"\n<BLOCKQUOTE><FONT size=+2><B><U>AGENCE DOMIMMO</U></B></FONT></BLOCKQUOTE>");
       fprintf(fichier,"\n<BLOCKQUOTE>Téléphone: 06 98 84 38 00 <BR>Fax: 04 93 42 34 66 <BR> Mail:
agencedomimmo@free.fr</BLOCKQUOTE><BR >");
       fprintf(fichier,"\n<FONT size=-1><CENTER><B>");
       fprintf(fichier,"\n\t<A href='appartement.html'><FONT color='black'>APPARTEMENTS</FONT></A>");
       fprintf(fichier,"\n\t<A href='maison.html'><FONT color='black'>MAISONS DE VILLAGE</FONT></A>\n\t<A href='villa.html'><FONT color='black'>VILLAS</FONT></A>\n\t<A href='location.html'><FONT color='black'>LOCATIONS</FONT></A>\n\t<A href='terrain.html'><FONT color='black'>TERRAINS</FONT></A>\n\t<A href='neuf.html'><FONT color='black'>NEUFS</FONT></A>\n\t<A href='/repertoire/formulaire.html'><FONT color='black'>NOUS CONTACTER</FONT></A>\n</B></CENTER></FONT>");
       fprintf(fichier,"<FONT SIZE=-1><CENTER><I><A href='appartements.html'><FONT color='black'>FLATS</FONT></A>\t<A href='maison.html'><FONT color='black'>HOUSES</FONT></A>\t<A href='villa.html'><FONT color='black'>VILLAS</FONT></A>\t<A href='location.html'><FONT color='black'>LOCATIONS</FONT></A>\t<A href='terrain.html'><FONT color='black'>LANDS</FONT></A>\t<A href='neuf.html'><FONT color='black'>NEUFS</FONT></A>\t<A href='/repertoire/formulaire.html'><FONT color='black'>CONTACT US</FONT></A></I></CENTER></FONT>");
       fprintf(fichier,"\n<BR>\n<CENTER><FONT size=+1 color='black'><B><U>%s</U></B></FONT></CENTER>\n<BR><BR>",titre_de_la_page);
       fprintf(fichier,"\n<CENTER><TABLE border=2 bgcolor='#9966FF' height='180'>");
       fprintf(fichier,"\n<TR>\n\t<TD  align='center' height=+10>\n\t\t<FONT size=-1><B><U>");
       fprintf(fichier,"\t\t\n %s",localisation);
       fprintf(fichier,"\t\t\n</U></B></FONT>\n\t</TD>\n\n\t<TD align='center'>\n\t\t<FONT size=-1><B><U>");
       fprintf(fichier,"\t\n\t %s",description);
       fprintf(fichier,"\n\t\t</U></B></FONT>\n\t</TD>\n</TR>\n\n<TR>\n\t<TD align='left'>");
       fprintf(fichier,"\n\t<IMG src='/image/%s' width='250' height='250'>\n\t</TD>",image);
       fprintf(fichier,"\n\n\t<TD width=500 valign='top'  bgcolor='#9966FF'>\n\t<BLOCKQUOTE>");
       fprintf(fichier,"\n\t\tVille: %s <BR>",localisation);
       fprintf(fichier,"\n\t\tType: %s <BR>",titre_de_la_page);
       fprintf(fichier,"\n\t\tSurface habitable: %ld m²<BR>",surface_habitable);
       fprintf(fichier,"\n\t\tSurface terrain: %ld m²<BR>",surface_terrain);
       fprintf(fichier,"\n\t\tRéférence: %d<BR>",reference);
       fprintf(fichier,"\n\t\tPrix: %ld euros<BR>",prix);
       fprintf(fichier,"<CENTER><HR width=200></CENTER>");
       fprintf(fichier,"\n\t\t%s\n<BR><BR>",description_detaillee);              
       fprintf(fichier,"\n\n\t<A href='/pdt_maison/%s.html'>",en_savoir_plus);
       fprintf(fichier,"\n<FONT color='red' size=+1><B>En savoir plus</B></FONT></A>");
       fprintf(fichier,"\n\n</BLOCKQUOTE></TD>\n</TR>\n</TABLE>\n</CENTER>");
 
      
      
      
      
        /*Creation de la page 'en savoir plus'*/
        printf("\n\tCreation de la page %s",en_savoir_plus);
                                        
        char nom_fichier[255];
             
              FILE *PLUS;
              sprintf((char *) &nom_fichier,"%s.html",en_savoir_plus);
              PLUS = fopen(nom_fichier,"w");
             
              if(PLUS == NULL)
              {
                      puts("\n\t\t---->LA PAGE HTML N'A PU ETRE CREE");
                      fclose(PLUS);
                      }
             
              else
              {
                      puts("\n\t\t---->CREATION DE LA PAGE HTML REUSSIE");
                      }
      
      
       /*Ecriture dans le fichier*/
      
       fprintf(PLUS,"<HTML>\n<HEAD>\n<TITLE>%s</TITLE>\n<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>\n\n",en_savoir_plus);
       fprintf(PLUS,"<!--*******************************************-->\n<!--*******************************************-->\n");
       fprintf(PLUS,"<SCRIPT language='JavaScript' type='text/javascript'>");
       fprintf(PLUS,"<!--\nfunction lance(selObj) {\n self.name=selectvaleur(selObj);\n self.location.href='/repertoire/formulaire.html';\n");
       fprintf(PLUS,"}\nfunction selectvaleur(sObj) {\nreturn sObj.options[sObj.selectedIndex].value;}//-->");
       fprintf(PLUS,"</SCRIPT>\n<!--*****************************************-->\n<!--*****************************************-->\n</HEAD>");
       fprintf(PLUS,"<BODY bgcolor='#9933FF' TOPMARGIN='50' BOTTOMMARGIN='50' LEFTMARGIN='60' RIGHTMARGIN='60'>\n<!--***********************************************************************************************************-->\n<!--***********************************************************************************************************-->\n<!-- DEBUT DU SCRIPT DIAPORAMA-->");
       fprintf(PLUS,"<script LANGUAGE='JavaScript'> \n var current = 0;\n function next(){ // forward one image\n if(document.formname.slide[current+1]){\ndocument.images.show.src = document.formname.slide[current+1].value;\ndocument.formname.slide.selectedIndex = ++current;}\nelse{first();}}");
       fprintf(PLUS,"\nfunction previous(){ // back on image\nif((current-1) >= 0){\ndocument.images.show.src = document.formname.slide[current-1].value;\ndocument.formname.slide.selectedIndex= --current;}\nelse{last();}}");
       fprintf(PLUS,"\nfunction first(){ // jump to first image\ncurrent=0;\ndocument.images.show.src = document.formname.slide[0].value;\ndocument.formname.slide.selectedIndex=0;}");
       fprintf(PLUS,"\nfunction last(){ // this is jump to last image\ncurrent=(document.formname.slide.length-1);\ndocument.images.show.src = document.formname.slide[current].value;\ndocument.formname.slide.selectedIndex=current;}");
       fprintf(PLUS,"\nfunction ap(text){ // this controls the auto-play and/or auto-stop\ndocument.formname.slidebutton.value=(text == 'Stop') ? 'Start' : 'Stop';\nrotate();}");
       fprintf(PLUS,"\nfunction change(){ // this is for the pulldown menu\ncurrent=document.formname.slide.selectedIndex;\ndocument.images.show.src = document.formname.slide[current].value;}\n\nfunction rotate() {\nif (document.formname.slidebutton.value == 'Stop') {\ncurrent = (current == document.formname.slide.length-1) ? 0 : current+1;\ndocument.images.show.src = document.formname.slide[current].value;\ndocument.formname.slide.selectedIndex = current;\nwindow.setTimeout('rotate()', 5000);}}\n// End --></script> </p>\n<!--FIN DU SCRIPT-->");
       fprintf(PLUS,"\n<BODY bgcolor='#9933FF' TOPMARGIN='50' BOTTOMMARGIN='50' LEFTMARGIN='60' RIGHTMARGIN='60'>");
       fprintf(PLUS,"\n<BLOCKQUOTE><FONT size=+2><B><U>AGENCE DOMIMMO</U></B></FONT></BLOCKQUOTE>");
       fprintf(PLUS,"\n<BLOCKQUOTE>Téléphone: 06 98 84 38 00 <BR>Fax: 04 93 42 34 66 <BR> Mail:
agencedomimmo@free.fr</BLOCKQUOTE><BR >");
       fprintf(PLUS,"\n<FONT size=-1><CENTER><B>");
       fprintf(PLUS,"\n\t<A href='appartement.html'><FONT color='black'>APPARTEMENTS</FONT></A>");
       fprintf(PLUS,"\n\t<A href='maison.html'><FONT color='black'>MAISONS DE VILLAGE</FONT></A>\n\t<A href='villa.html'><FONT color='black'>VILLAS</FONT></A>\n\t<A href='location.html'><FONT color='black'>LOCATIONS</FONT></A>\n\t<A href='terrain.html'><FONT color='black'>TERRAINS</FONT></A>\n\t<A href='neuf.html'><FONT color='black'>NEUFS</FONT></A>\n\t<A href='/repertoire/formulaire.html'><FONT color='black'>NOUS CONTACTER</FONT></A>\n</B></CENTER></FONT>");
       fprintf(PLUS,"<FONT SIZE=-1><CENTER><I><A href='appartements.html'><FONT color='black'>FLATS</FONT></A>\t<A href='maison.html'><FONT color='black'>HOUSES</FONT></A>\t<A href='villa.html'><FONT color='black'>VILLAS</FONT></A>\t<A href='location.html'><FONT color='black'>LOCATIONS</FONT></A>\t<A href='terrain.html'><FONT color='black'>LANDS</FONT></A>\t<A href='neuf.html'><FONT color='black'>NEUFS</FONT></A>\t<A href='/repertoire/formulaire.html'><FONT color='black'>CONTACT US</FONT></A></I></CENTER></FONT>");
       fprintf(PLUS,"\n<BR>\n<CENTER><FONT size=+1 color='black'><B><U>%s</U></B></FONT></CENTER>\n<BR><BR>",titre_de_la_page);
       fprintf(PLUS,"\n<CENTER>\n<TABLE border=2 bgcolor='#9966FF'>\n<TR>\n\t<TD align='center' height=10><FONT size=-1><B><U>%s</U></B></FONT></TD>",localisation);
       fprintf(PLUS,"\n<TD align='center'><FONT size=-1><B><U>%s</U></B></FONT></TD>",description);
       fprintf(PLUS,"\n</TR>\n<TR>\n<TD align='left' width=200 height=200>\n<form name='formname'>\n<div align='center'><center><table cellspacing='1' cellpadding='4' bgcolor='#000000'>");
       fprintf(PLUS,"\n<TR><TD align='center' bgcolor='white' width='200' height='150'>\n<img src='/image/%s' name='show' WIDTH='450' HEIGHT='350'>",image);
       fprintf(PLUS,"\n</TD>\n</TR>\n <TR>\n<TD align='center' bgcolor='#C0C0C0'><select name='slide' onChange='change();' size='1'>");
       fprintf(PLUS,"\n<option value='/image/%s' selected>%s</option>",image,commentaire1);
       fprintf(PLUS,"\n<option value='/image/%s'>%s</option>",image2,commentaire2);
       fprintf(PLUS,"\n<option value='/image/%s'>%s</option>",image3,commentaire3);
       fprintf(PLUS,"\n</select>\n</TD>\n</TR>\n<TR>\n<TD align='center' bgcolor='#C0C0C0'>");
       fprintf(PLUS,"\n<input type='button' onclick='first();' value='<<' title='<<' style='border:1 SOLID #e6e6e6;'>");
       fprintf(PLUS,"\n<input type='button' onclick='previous();' value='&lt;&lt;' title='<' style='border:1 SOLID #e6e6e6;'>");
       fprintf(PLUS,"\n<input type='button' onclick='next();' value='&gt;&gt;' title='>' style='border:1 SOLID #e6e6e6;'>");
       fprintf(PLUS,"\n<input type='button' onclick='last();' value='>>' title='>>' style='border:1 SOLID #e6e6e6;'>");
       fprintf(PLUS,"\n</TD>\n</TR>\n</TD>\n</TABLE>\n</center>\n</div>\n</form>\n<!-- FIN DU SCRIPT DIAPORAMA-->");
       fprintf(PLUS,"\n\n<TD width=500 valign='top'  bgcolor='#9966FF'><BLOCKQUOTE><B>");
       fprintf(PLUS,"\n\t\tVille: %s <BR>",localisation);
       fprintf(PLUS,"\n\t\tType: %s <BR>",titre_de_la_page);
       fprintf(PLUS,"\n\t\tSurface habitable: %ld m²<BR>",surface_habitable);
       fprintf(PLUS,"\n\t\tSurface terrain: %ld m²<BR>",surface_terrain);
       fprintf(PLUS,"\n\t\tRéférence: %d<BR>",reference);
       fprintf(PLUS,"\n\t\tPrix: %ld euros<BR>",prix);
       fprintf(PLUS,"\n<BR><BR>\n<CENTER>\n<HR width=200>\n</CENTER>%s",description_detaillee);
       fprintf(PLUS,"\n<BR><BR>\n<A href='maison.html'><FONT size=-1><U><B><FONT color='black'>RETOUR A LA PAGE  PRECEDENTE</FONT></B></U></A>");
       fprintf(PLUS,"\n<BR><BR>\n<FORM action='/repertoire/formulaire.html' name='eform' onSubmit='lance(document.eform.nombre);return false'>Référence :<SELECT name='nombre' size='1'>\n<OPTION value='%d'> %d</OPTION>",reference,reference);
       fprintf(PLUS,"\n</SELECT>\n<INPUT type=submit value='Signaler mon interêt pour ce produit'>\n</FORM>\n</B></BLOCKQUOTE>\n</TD>\n</TR>\n</TABLE>\n</CENTER>\n</BODY>\n</HTML>");
      
       fclose(PLUS);
 
       fflush(stdin);
 
       free(localisation);
       free(description);
       free(image);
       free(image2);
       free(image3);
       free(description_detaillee);
       free(en_savoir_plus); 
       free(commentaire1);                                   
       free(commentaire2);
       free(commentaire3);
      
       printf("\n\tCREATION DE LA PAGE %s ACHEVEE\n",en_savoir_plus);
   }
      
   puts("\n\n\t\tSORTIE DE LA BOUCLE for");
   getch();  
      
   fprintf(fichier,"\n\n</BODY>\n</HTML>");
   
  
/*On ferme les fichiers*/
   fclose(fichier);
   
  
/*On libère la mémoire*/
   free(nom_de_la_page);
   free(titre_de_la_page);
   free(localisation);
   free(description);
   free(image);
   free(image2);
   free(image3);
   free(description_detaillee);
   free(en_savoir_plus); 
   free(commentaire1);                                   
   free(commentaire2);
   free(commentaire3);
   
   puts("\n\n\tFERMETURE DU FICHIER EFFECTUEE");
  
   getch();
}
mardi 28 août 2007 à 11:57:27 | Re : Le programme plante à la fin

juju12

Et ça plante à quel endroit, quel message d'erreur?
mardi 28 août 2007 à 12:09:15 | Re : Le programme plante à la fin

juju12

En fait problème repéré tu ne dois pas faire free(localisation)...jusqu'à free(commentaire3) dans ta boucle for puisque tu es censé pouvoir les réutiliser et de toutes façons tu le fais une deuxième fois après la boucle => plantage puisque ressources déjà libérées, les pointeurs ne sont plus valides.
Ce problème réglé ça tourne correctement.
mardi 28 août 2007 à 12:14:00 | Re : Le programme plante à la fin

milhandril

Si c'est un problème de boucle essai avec
for(nombre_reference = 0;nombre_reference < nombre_de_produit - 1;nombre_reference++)

c'est tout bete mais ca regle un pb de for sur 2

mardi 28 août 2007 à 13:18:01 | Re : Le programme plante à la fin

deguelator

Ok merci. Mais si je veux creer au moins 2 produits, cela ne fonctionne pas. Pour le premier sa passe. Mais le second non. Il ne se passe plus lorsque que le message           puts("\n\t\t---->CREATION DE LA PAGE HTML REUSSIE");  s'affiche.
mardi 28 août 2007 à 13:53:02 | Re : Le programme plante à la fin

juju12

Fais pas ce que t'as dit milhandril c'est faux (suffit de savoir compter pour régler les conditions de boucle, pas de bricoler jusqu'à ce que ça marche).
J'ai essayé chez moi après la correction que je t'ai donnée et il y a bien création de 2 produits.
mardi 28 août 2007 à 14:07:57 | Re : Le programme plante à la fin

deguelator

ben oui j'ai fait ce que tu as dit mais le programme ne fini pas correctement puisqu'il bug au message. Je peux pas faire plus de 2 pages html. Et la page que l'on creer en tout premier avant la boucle for et vide.
mardi 28 août 2007 à 14:28:04 | Re : Le programme plante à la fin

deguelator

Si je veux creer 2 produits, alors il va y avoir dans un premier temps la création d'une première page qui contiendra le listing des produits. Pour chaque produit, on créé une nouvelle page HTML (créée lors de la boucle FOR). Alors pour 2 produits j'aurais 3 pages.

Le problème c'est que si j'éxecute le programme j'aurais bien 3 pages. Mais celle récapitulant les produits est vide. Il y a une erreur à la fin de la création d'une page spécifique à un produit (fin boucle FOR). Donc je peux pas créer plus de 2 produits.
mardi 28 août 2007 à 16:24:08 | Re : Le programme plante à la fin

juju12

Je comprends pas, chez moi il y a bien création de 3 pages avec les contenus désirés (listing, détail1, détail2). Tu peux reposter ton code avec les modifs que tu y as ajoutées?
mardi 28 août 2007 à 17:51:34 | Re : Le programme plante à la fin

deguelator

J'ai ajouté quelques variables en plus.

#include <stdio.h>
#include <conio.h>
#include <malloc.h>
#include <string.h>


int main()
{
        /*
   Déclaration de l'ensemble des variables
   */
  
   char *nom_de_la_page, *titre_de_la_page, *localisation, *description, *image, *image2, *image3, *description_detaillee , *en_savoir_plus;
   char *commentaire1, *commentaire2, *commentaire3 , *lien_page_suivante , *lien_page_precedente, *nom_repertoire;
   int prix, reference, surface_terrain, surface_habitable, nombre_de_produit , nombre_reference;
  
   nom_de_la_page = (char *)malloc(20);
   titre_de_la_page = (char *)malloc(20);
   localisation = (char *)malloc(20);
   description = (char *)malloc(30);
   image = (char *)malloc(20);
   description_detaillee = (char *)malloc(200);
   en_savoir_plus = (char *)malloc(20);
   image2 = (char *)malloc(20);
   image3 = (char *)malloc(20);
   commentaire1 = (char *)malloc(20);
   commentaire2 = (char *)malloc(20);
   commentaire3 = (char *)malloc(20);
   lien_page_suivante = (char *)malloc(20);
   lien_page_precedente = (char *)malloc(20);
   nom_repertoire = (char *)malloc(20);
  
   nombre_reference = 0;
  
  
 
   /*
   Debut du traitement
   */
  
   puts("\nCombien de produits desirez-vous ajouter?");
   scanf("%d",&nombre_de_produit);
  
   fflush(stdin);
  
  
   /*Saisie du nom et du titre de la page*/
  
   puts("\nSaisir le nom de la page:");
   gets(nom_de_la_page);
  
   puts("\nSaisir le titre de la page:");
   gets(titre_de_la_page);
  
  
   /*Creation du listing*/
  
   printf("\n\tCreation de la page %s",nom_de_la_page);
                                        
   char filename[255];
             
   FILE *fichier;
   sprintf((char *) &filename,"%s.html",nom_de_la_page);
   fichier = fopen(filename,"w");
  
  
   /*Gestion des erreurs*/
                                                
   if(fichier == NULL)
   {
              puts("\n\t\t---->LA PAGE HTML N'A PU ETRE CREE");
              fclose(fichier);
   }
                                                
   else
   {
              puts("\n\t\t---->CREATION DE LA PAGE HTML REUSSIE");
   }
   
   
    /*Première écriture dans le fichier*/
   
    fprintf(fichier,"<HTML>\n<HEAD>\n<TITLE>%s</TITLE>\n</HEAD>",nom_de_la_page);
    fprintf(fichier,"\n<BODY bgcolor='#9933FF' TOPMARGIN='50' BOTTOMMARGIN='50' LEFTMARGIN='60' RIGHTMARGIN='60'>");
    fprintf(fichier,"\n<BLOCKQUOTE><FONT size=+2><B><U>AGENCE DOMIMMO</U></B></FONT></BLOCKQUOTE>");
    fprintf(fichier,"\n<BLOCKQUOTE>Téléphone: 06 98 84 38 00 <BR>Fax: 04 93 42 34 66 <BR> Mail:
agencedomimmo@free.fr</BLOCKQUOTE><BR >");
    fprintf(fichier,"\n<FONT size=-1><CENTER><B>");
    fprintf(fichier,"\n\t<A href='appartement.html'><FONT color='black'>APPARTEMENTS</FONT></A>");
    fprintf(fichier,"\n\t<A href='maison.html'><FONT color='black'>MAISONS DE VILLAGE</FONT></A>\n\t<A href='villa.html'><FONT color='black'>VILLAS</FONT></A>\n\t<A href='location.html'><FONT color='black'>LOCATIONS</FONT></A>\n\t<A href='terrain.html'><FONT color='black'>TERRAINS</FONT></A>\n\t<A href='neuf.html'><FONT color='black'>NEUFS</FONT></A>\n\t<A href='/repertoire/formulaire.html'><FONT color='black'>NOUS CONTACTER</FONT></A>\n</B></CENTER></FONT>");
    fprintf(fichier,"<FONT SIZE=-1><CENTER><I><A href='appartements.html'><FONT color='black'>FLATS</FONT></A>\t<A href='maison.html'><FONT color='black'>HOUSES</FONT></A>\t<A href='villa.html'><FONT color='black'>VILLAS</FONT></A>\t<A href='location.html'><FONT color='black'>LOCATIONS</FONT></A>\t<A href='terrain.html'><FONT color='black'>LANDS</FONT></A>\t<A href='neuf.html'><FONT color='black'>NEUFS</FONT></A>\t<A href='/repertoire/formulaire.html'><FONT color='black'>CONTACT US</FONT></A></I></CENTER></FONT>");                                   
 
  
   for(nombre_reference;nombre_reference < nombre_de_produit;nombre_reference++)
   {
                                        
                                         /*Saisie des variables de type caractère*/
                                        
                                         puts("\nSaisir la localisation du produit:");
                                         gets(localisation);
                                        
                                         puts("\nSaisir une description succinte du produit:");
                                         gets(description);
                                        
                                         puts("\nSaisir le nom de l'image a afficher en indiquant son format:");
                                         gets(image);
                                        
                                         puts("\nSaisir le commentaire:");
                                         gets(commentaire1);
                                        
                                         puts("\nSaisir le nom de l'image2:");
                                         gets(image2);
                                        
                                         puts("\nSaisir le commentaire:");
                                         gets(commentaire2);
                                        
                                         puts("\nSaisir le nom de l'image 3:");
                                         gets(image3);
                                        
                                         puts("\nSaisir le commentaire:");
                                         gets(commentaire3);
                                        
                                         puts("\nSaisir la description detaillee du produit:");
                                         gets(description_detaillee);
                                        
                                         puts("\nSaisir le nom de la page 'en savoir plus'");
                                         gets(en_savoir_plus);
                                        
                                         puts("\nSaisir le nom de la page precedente:");
                                         gets(lien_page_precedente);
                                        
                                         puts("\nSaisir le nom de la page suivante:");
                                         gets(lien_page_suivante);
                                        
                                         puts("Indiquer le repertoire dans lequel vous desirez ajouter le fichier");
                                         gets(nom_repertoire);
                                        
                                         /*Saisie des variables de type entiers*/
                                         puts("\nSaisir la surface habitable");
                                         scanf("%d",&surface_habitable);
                                        
                                         puts("\nSaisir la surface du terrain:");
                                         scanf("%d",&surface_terrain);
                                        
                                         puts("\nSaisir la reference du produit:");
                                         scanf("%d",&reference);
                                        
                                         puts("\nSaisir le prix:");
                                         scanf("%d",&prix);
                                        
                                        
                                                  /*
                                                     Ecriture dans le listing
                                                  */
      
       fprintf(fichier,"\n<BR>\n<CENTER><FONT size=+1 color='black'><B><U>%s</U></B></FONT></CENTER>\n<BR><BR>",titre_de_la_page);
       fprintf(fichier,"\n<CENTER><TABLE border=2 bgcolor='#9966FF' height='180'>");
       fprintf(fichier,"\n<TR>\n\t<TD  align='center' height=+10>\n\t\t<FONT size=-1><B><U>");
       fprintf(fichier,"\t\t\n %s",localisation);
       fprintf(fichier,"\t\t\n</U></B></FONT>\n\t</TD>\n\n\t<TD align='center'>\n\t\t<FONT size=-1><B><U>");
       fprintf(fichier,"\t\n\t %s",description);
       fprintf(fichier,"\n\t\t</U></B></FONT>\n\t</TD>\n</TR>\n\n<TR>\n\t<TD align='left'>");
       fprintf(fichier,"\n\t<IMG src='/image/%s' width='250' height='250'>\n\t</TD>",image);
       fprintf(fichier,"\n\n\t<TD width=500 valign='top'  bgcolor='#9966FF'>\n\t<BLOCKQUOTE>");
       fprintf(fichier,"\n\t\tVille: %s <BR>",localisation);
       fprintf(fichier,"\n\t\tType: %s <BR>",titre_de_la_page);
       fprintf(fichier,"\n\t\tSurface habitable: %ld m²<BR>",surface_habitable);
       fprintf(fichier,"\n\t\tSurface terrain: %ld m²<BR>",surface_terrain);
       fprintf(fichier,"\n\t\tRéférence: %d<BR>",reference);
       fprintf(fichier,"\n\t\tPrix: %ld euros<BR>",prix);
       fprintf(fichier,"<CENTER><HR width=200></CENTER>");
       fprintf(fichier,"\n\t\t%s\n<BR><BR>",description_detaillee);              
       fprintf(fichier,"\n\n\t<A href='/%s/%s.html'>",nom_repertoire,en_savoir_plus);
       fprintf(fichier,"\n<FONT color='red' size=+1><B>En savoir plus</B></FONT></A>");
       fprintf(fichier,"\n\n</BLOCKQUOTE></TD>\n</TR>\n</TABLE>\n</CENTER>");
 
      
      
      
      
        /*Creation de la page 'en savoir plus'*/
        printf("\n\tCreation de la page %s",en_savoir_plus);
                                        
        char nom_fichier[255];
             
              FILE *PLUS;
              sprintf((char *) &nom_fichier,"%s.html",en_savoir_plus);
              PLUS = fopen(nom_fichier,"w");
             
              if(PLUS == NULL)
              {
                      puts("\n\t\t---->LA PAGE HTML N'A PU ETRE CREE");
                      fclose(PLUS);
                      }
             
              else
              {
                      puts("\n\t\t---->CREATION DE LA PAGE HTML REUSSIE");
                      }
      
      
       /*Ecriture dans le fichier*/
      
       fprintf(PLUS,"<HTML>\n<HEAD>\n<TITLE>%s</TITLE>\n<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>\n\n",en_savoir_plus);
       fprintf(PLUS,"<!--*******************************************-->\n<!--*******************************************-->\n");
       fprintf(PLUS,"<SCRIPT language='JavaScript' type='text/javascript'>");
       fprintf(PLUS,"<!--\nfunction lance(selObj) {\n self.name=selectvaleur(selObj);\n self.location.href='/repertoire/formulaire.html';\n");
       fprintf(PLUS,"}\nfunction selectvaleur(sObj) {\nreturn sObj.options[sObj.selectedIndex].value;}//-->");
       fprintf(PLUS,"</SCRIPT>\n<!--*****************************************-->\n<!--*****************************************-->\n</HEAD>");
       fprintf(PLUS,"<BODY bgcolor='#9933FF' TOPMARGIN='50' BOTTOMMARGIN='50' LEFTMARGIN='60' RIGHTMARGIN='60'>\n<!--***********************************************************************************************************-->\n<!--***********************************************************************************************************-->\n<!-- DEBUT DU SCRIPT DIAPORAMA-->");
       fprintf(PLUS,"<script LANGUAGE='JavaScript'> \n var current = 0;\n function next(){ // forward one image\n if(document.formname.slide[current+1]){\ndocument.images.show.src = document.formname.slide[current+1].value;\ndocument.formname.slide.selectedIndex = ++current;}\nelse{first();}}");
       fprintf(PLUS,"\nfunction previous(){ // back on image\nif((current-1) >= 0){\ndocument.images.show.src = document.formname.slide[current-1].value;\ndocument.formname.slide.selectedIndex= --current;}\nelse{last();}}");
       fprintf(PLUS,"\nfunction first(){ // jump to first image\ncurrent=0;\ndocument.images.show.src = document.formname.slide[0].value;\ndocument.formname.slide.selectedIndex=0;}");
       fprintf(PLUS,"\nfunction last(){ // this is jump to last image\ncurrent=(document.formname.slide.length-1);\ndocument.images.show.src = document.formname.slide[current].value;\ndocument.formname.slide.selectedIndex=current;}");
       fprintf(PLUS,"\nfunction ap(text){ // this controls the auto-play and/or auto-stop\ndocument.formname.slidebutton.value=(text == 'Stop') ? 'Start' : 'Stop';\nrotate();}");
       fprintf(PLUS,"\nfunction change(){ // this is for the pulldown menu\ncurrent=document.formname.slide.selectedIndex;\ndocument.images.show.src = document.formname.slide[current].value;}\n\nfunction rotate() {\nif (document.formname.slidebutton.value == 'Stop') {\ncurrent = (current == document.formname.slide.length-1) ? 0 : current+1;\ndocument.images.show.src = document.formname.slide[current].value;\ndocument.formname.slide.selectedIndex = current;\nwindow.setTimeout('rotate()', 5000);}}\n// End --></script> </p>\n<!--FIN DU SCRIPT-->");
       fprintf(PLUS,"\n<BODY bgcolor='#9933FF' TOPMARGIN='50' BOTTOMMARGIN='50' LEFTMARGIN='60' RIGHTMARGIN='60'>");
       fprintf(PLUS,"\n<BLOCKQUOTE><FONT size=+2><B><U>AGENCE DOMIMMO</U></B></FONT></BLOCKQUOTE>");
       fprintf(PLUS,"\n<BLOCKQUOTE>Téléphone: 06 98 84 38 00 <BR>Fax: 04 93 42 34 66 <BR> Mail:
agencedomimmo@free.fr</BLOCKQUOTE><BR >");
       fprintf(PLUS,"\n<FONT size=-1><CENTER><B>");
       fprintf(PLUS,"\n\t<A href='appartement.html'><FONT color='black'>APPARTEMENTS</FONT></A>");
       fprintf(PLUS,"\n\t<A href='maison.html'><FONT color='black'>MAISONS DE VILLAGE</FONT></A>\n\t<A href='villa.html'><FONT color='black'>VILLAS</FONT></A>\n\t<A href='location.html'><FONT color='black'>LOCATIONS</FONT></A>\n\t<A href='terrain.html'><FONT color='black'>TERRAINS</FONT></A>\n\t<A href='neuf.html'><FONT color='black'>NEUFS</FONT></A>\n\t<A href='/repertoire/formulaire.html'><FONT color='black'>NOUS CONTACTER</FONT></A>\n</B></CENTER></FONT>");
       fprintf(PLUS,"<FONT SIZE=-1><CENTER><I><A href='appartements.html'><FONT color='black'>FLATS</FONT></A>\t<A href='maison.html'><FONT color='black'>HOUSES</FONT></A>\t<A href='villa.html'><FONT color='black'>VILLAS</FONT></A>\t<A href='location.html'><FONT color='black'>LOCATIONS</FONT></A>\t<A href='terrain.html'><FONT color='black'>LANDS</FONT></A>\t<A href='neuf.html'><FONT color='black'>NEUFS</FONT></A>\t<A href='/repertoire/formulaire.html'><FONT color='black'>CONTACT US</FONT></A></I></CENTER></FONT>");
       fprintf(PLUS,"\n<BR>\n<CENTER><FONT size=+1 color='black'><B><U>%s</U></B></FONT></CENTER>\n<BR><BR>",titre_de_la_page);
       fprintf(PLUS,"\n<CENTER>\n<TABLE border=2 bgcolor='#9966FF'>\n<TR>\n\t<TD align='center' height=10><FONT size=-1><B><U>%s</U></B></FONT></TD>",localisation);
       fprintf(PLUS,"\n<TD align='center'><FONT size=-1><B><U>%s</U></B></FONT></TD>",description);
       fprintf(PLUS,"\n</TR>\n<TR>\n<TD align='left' width=200 height=200>\n<form name='formname'>\n<div align='center'><center><table cellspacing='1' cellpadding='4' bgcolor='#000000'>");
       fprintf(PLUS,"\n<TR><TD align='center' bgcolor='white' width='200' height='150'>\n<img src='/image/%s' name='show' WIDTH='450' HEIGHT='350'>",image);
       fprintf(PLUS,"\n</TD>\n</TR>\n <TR>\n<TD align='center' bgcolor='#C0C0C0'><select name='slide' onChange='change();' size='1'>");
       fprintf(PLUS,"\n<option value='/image/%s' selected>%s</option>",image,commentaire1);
       fprintf(PLUS,"\n<option value='/image/%s'>%s</option>",image2,commentaire2);
       fprintf(PLUS,"\n<option value='/image/%s'>%s</option>",image3,commentaire3);
       fprintf(PLUS,"\n</select>\n</TD>\n</TR>\n<TR>\n<TD align='center' bgcolor='#C0C0C0'>");
       fprintf(PLUS,"\n<input type='button' onclick='first();' value='<<' title='<<' style='border:1 SOLID #e6e6e6;'>");
       fprintf(PLUS,"\n<input type='button' onclick='previous();' value='&lt;&lt;' title='<' style='border:1 SOLID #e6e6e6;'>");
       fprintf(PLUS,"\n<input type='button' onclick='next();' value='&gt;&gt;' title='>' style='border:1 SOLID #e6e6e6;'>");
       fprintf(PLUS,"\n<input type='button' onclick='last();' value='>>' title='>>' style='border:1 SOLID #e6e6e6;'>");
       fprintf(PLUS,"\n</TD>\n</TR>\n</TD>\n</TABLE>\n</center>\n</div>\n</form>\n<!-- FIN DU SCRIPT DIAPORAMA-->");
       fprintf(PLUS,"\n\n<TD width=500 valign='top'  bgcolor='#9966FF'><BLOCKQUOTE><B>");
       fprintf(PLUS,"\n\t\tVille: %s <BR>",localisation);
       fprintf(PLUS,"\n\t\tType: %s <BR>",titre_de_la_page);
       fprintf(PLUS,"\n\t\tSurface habitable: %ld m²<BR>",surface_habitable);
       fprintf(PLUS,"\n\t\tSurface terrain: %ld m²<BR>",surface_terrain);
       fprintf(PLUS,"\n\t\tRéférence: %d<BR>",reference);
       fprintf(PLUS,"\n\t\tPrix: %ld euros<BR>",prix);
       fprintf(PLUS,"\n<BR><BR>\n<CENTER>\n<HR width=200>\n</CENTER>%s",description_detaillee);
       fprintf(PLUS,"\n<BR><BR>\n<A href='http://agencedomimmo.free.fr/n%s.html'><FONT size=-1><U><B><FONT color='black'>RETOUR A LA PAGE PRECEDENTE</FONT></B></U></A>",nom_de_la_page);
       fprintf(PLUS,"\n<BR><BR>\n<FORM action='/repertoire/formulaire.html' name='eform' onSubmit='lance(document.eform.nombre);return false'>Référence :<SELECT name='nombre' size='1'>\n<OPTION value='%d'> %d</OPTION>",reference,reference);
       fprintf(PLUS,"\n</SELECT>\n<INPUT type=submit value='Signaler mon interêt pour ce produit'>\n</FORM>\n</B></BLOCKQUOTE>\n</TD>\n</TR>\n</TABLE>\n</CENTER>\n</BODY>\n</HTML>");
      
       printf("Fichier %s créé.",en_savoir_plus);
      
       fclose(PLUS);
 
       fflush(stdin);
 
       free(localisation);
       free(description);
       free(image);
       free(image2);
       free(image3);
       free(description_detaillee);
       free(en_savoir_plus); 
       free(commentaire1);                                   
       free(commentaire2);
       free(commentaire3);
      
      
   }
      
   puts("\n\n\t\tSORTIE DE LA BOUCLE for");
     
   
   fprintf(fichier," \n\n\n<BR><BR>\n<CENTER>");
   fprintf(fichier,"\n<A href='%s.html'><FONT color='black' size=+1><B>Page précèdente</B></FONT></A>",lien_page_suivante);
   fprintf(fichier,"\n<A href='%s.html'><FONT color='black' size=+1><B>Page suivante</B></FONT></A>\n</CENTER>",lien_page_precedente);
   fprintf(fichier,"\n\n</BODY>\n</HTML>");
   
   /*On ferme les fichiers*/
   fclose(fichier);
   
   /*On libère la mémoire*/
   free(nom_de_la_page);
   free(titre_de_la_page);
   free(lien_page_suivante);
   free(lien_page_precedente);
   free(nom_repertoire);
  
   
   puts("\n\n\tFERMETURE DU FICHIER EFFECTUEE");
  
   getch();
}
    

    
    

                               

 

 

 


1 2

Cette discussion est classée dans : fichier, page, puts, free, fprintf


Répondre à ce message

Sujets en rapport avec ce message

lancement d une page html par un fichier exe ecirt en c [ par leplaideur ] #includemain(void){ system("E/index.html");}il m affiche "nom de commande ou fichier incorrect"Quelle est mon erreur? pb ecriture ds fichier [ par YOHANONEILL ] bonjour, voila j'ai un programme ou j'écrit dans un fichier des lignes, mais parfois la ligne que j'insert dans le fichier s'écrit 20000 ou 60000 foi fprintf overload ??? [ par ekinox17 ] bonjour, je sauvagarde un historique de mesure toutes les 10 seconde via fprintf donc l'ecriture dans le fichier se fait en mode "a" et donc elle est enregistrement/connezction simple [ par stefbuet ] bonjour, comment peut t'on faire pour qu'il y est dans une premiere page 2 champs de texte de saisie, un pour le pseudo, et un pour un pass, et _n bou svp aidez moi!!!je ve crée1 .exe y connait rien! [ par punitzion ] svp aidez moi!!!personne n'arrive a me repondre sa doit pourtant pas étre compliquer pour des personnes qui maitrise les languages de programmationbon programme en C [ par rosco91 ] bonjour, cela fait deux jour que je cherche un programme qui me permettra de lire plusieur fichiers textes existants dans un dossier. J'ai un programm les class [ par snpier wolf ] bonjour voila j'ais commancer un peux a programmé avec les class.et j'ais un problème que je n'arrive pas à résoudre.voila le bou de codeclass command pb encoding Base64 [ par mailer ] J'ai récupéré cette méthode pour encoder un fichier en base64 mais elle plante au niveau du 1er fprintf. Quelqu'un a t-il une solution??? Merci #defi Ecrire dans un fichier [ par pitidragon ] Bonjour !Je viens vous demandez de l'aide pour un programme en C. J'ai réalisé un démineur, jouable sur console, et je dois rajouter une fonction mais fonction fread() [ par cacoucatatonique ] salut a tous, et oui c'est encore moi mais bon javoue que ca me donne du fil a retordre.voila je suis en train de faire un programme qui doit ecrire d


Nos sponsors


Appels d'offres

Sondage...

Comparez les prix


HTC Hero

Entre 550€ et 550€

CalendriCode

Mars 2010
LMMJVSD
1234567
891011121314
15161718192021
22232425262728
293031    

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,359 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales