begin process at 2008 07 20 23:07:07
1 213 497 membres
398 nouveaux aujourd'hui
14 167 membres club

Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum.
Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

Sujet : encadre un texte en c/c++ [ Divers / Débutant(e) ] (lil_adriano)

encadre un texte en c/c++ le 18/11/2007 03:52:22

lil_adriano
Slt tout le monde
je debute en C/C++ je voudrai faire cadre  pour un mot mais j'y arrive pas.
j'ai essayer de faire un mais on peu pas faire un mot corret.

voici mon code source

#include <stdio.h>

main()
{
      int i,tabl,j,larg;
     
tabl=37;
larg=9;


for (int i=0; i < tabl;i++)
{
    printf("#");
}
printf("\n");

for(int i=0; i<larg;i++)
{
        printf("|");
        for(int j = 0; j < i ; j++) //
    {
        printf( " ");
    }
   
   
    for(int j = 0; j < tabl - 2 - i; j++) //
    {
        printf( " ");
    }printf( "|\n");
}

for (int i=0; i < tabl;i++)
{
    printf("#");
}
printf("\n");
scanf("%d",&tabl);

return 0;
}

j'utilise devc++.
j'espere que vous apporterai une aide a mon probleme. merci

Re : encadre un texte en c/c++ le 18/11/2007 18:18:20

yann_lo_san
Réponse acceptée !

Voici une fonction permettant d'encadrer un texte de longueur variable sur la console.
Les constantes veulent dire
cadre haut gauche
cadre bas gauche
ect...

#include <stdio.h>
#include <tchar.h>
#include <stdlib.h>

static

const unsigned char CHG =201;
static const unsigned char CBG =200;
static const unsigned char CHD =187;
static const unsigned char CBD =188;
static const unsigned char LHB =205;
static const unsigned char LL =186;

// FONCTION ENCADRE TEXTE

void

EncadreTexte(char* texte,bool tab )
{
   
int lg =strlen(texte);
   
char * str1 =newchar[(lg+1)+12];
   
str1[lg+12]='\0';

    memset (str1,'.', lg);
   
_strset (str1, LHB);

   
if (tab)printf("\t");
   
printf ( "%c%s%c \n" , CHG, str1, CHD);
   
if (tab)printf("\t");
   
printf ( "%c %s %c \n" , LL, texte, LL);
   
if (tab)printf("\t");
   
printf ( "%c%s%c \n\n" , CBG, str1, CBD);
   
    if (str1)delete[] str1 ;
}

// MAIN

int

_tmain ( int argc,_TCHAR* argv [])
{
   
EncadreTexte("UN TEXTE A ENCADRER", true);
   
return 0 ;
}

Re : encadre un texte en c/c++ le 18/11/2007 18:30:14

titof3812
Réponse acceptée !
Salut

quelque petit pb sur ton prog

tu redeclare a chaque fois un nouvel int i dans les boucle for (inutile) et ne passe pas sur un compilateur gcc.

ci dessous un morceau de code qui passe en utilisant ta methede de boucle for mais tu devrait regarder les chaines de format  du printf ca allegerais le code

#include <stdio.h>

main()
{
int i,tabl,j,larg,len;
    
tabl=37;
larg=9;

char chaine[25];
printf ("entrez la chaine a ecrire (max 24 char) :");
scanf ("%24s",&chaine),
len=strlen(chaine);

printf ("entrer le nb de colonne : ");
scanf("%d",&tabl);
if (tabl <len+2)
    tabl=len+2;

for (i=0; i < tabl;i++)
   printf("#");
printf("\n");

for(i=0; i<larg/2;i++)
    {
        printf("|");
        for(j = 0; j < tabl-2 ; j++) //
            printf( " ");
    printf( "|\n");
    }

printf("|");
for (i=1;i<(tabl-len)/2;i++)
    printf (" ");
printf(chaine);
for (j=i+len;j<tabl-1;j++)
    printf(" ");
printf("|\n");


for(i=0; i<larg/2;i++)
    {
        printf("|");
        for(j = 0; j < tabl-2 ; j++) //
            printf( " ");
    printf( "|\n");
    }


for (i=0; i < tabl;i++)
    printf("#");
printf("\n");
//

return 0;
}
 



Re : encadre un texte en c/c++ le 19/11/2007 01:55:14

lil_adriano

Merci de m'avoir repondu aussi vite. mais dans vos codes je suis confronter a un probleme c'est strlen ca me dit:
   `strlen' undeclared (first use this function)
  (Each undeclared identifier is reported only once for each function it appears in.)

je tenterai d'arranger ce petit probleme sinon je fais appel a vous. Merci encore.



Re : encadre un texte en c/c++ le 19/11/2007 02:03:53

lil_adriano

Heu re salut c'est encore moi yann_lo_san la  j'ai un probleme avec ton code sources ca me dis:

  In function `void EncadreTexte(char*, bool)':
`strlen' undeclared (first use this function)
  (Each undeclared identifier is reported only once for each function it appears in.)
`newchar' undeclared (first use this function) 
`memset' undeclared (first use this function) 
`_strset' undeclared (first use this function)

donc tu pourra me dire comment resoudre se probleme?  je vais essayer de mon cote mais ta lumiere ne serai pas de refus.

logiciel utilisé: devc++ peut etre ca pourra aide.


Re : encadre un texte en c/c++ le 19/11/2007 08:45:21

titof3812
Salut lil_adriano

Jái essaye le code ussi mais ce n'est pas de l'ANSI C Je lái modifie mais la je suis au boulot ;
Je te renvoie ca a midi ou  ce soir .
 Le fait que tu ne vois pas strlen est etrange ca fait partie sdu C standard.
( táurais pas des option de compilation C++ ??? ....... )


Re : encadre un texte en c/c++ le 19/11/2007 09:03:49

titof3812
pour le probleme de strlen ca devrait etre resolu en rajoutant un

#include < string.h>  ou
#include < Cstring.h>  

good luck

Re : encadre un texte en c/c++ le 19/11/2007 09:12:49

yann_lo_san

#include <string> devrait résoudre le problème.

Pour newchar c'est un espace manquant, c'est bien sur :
new char

Re : encadre un texte en c/c++ le 19/11/2007 12:14:35

titof3812
Salut lil la version de yann passee en C ANSI tu devrais pouvoir la compiler sans trop de pb. NB : j'ai rajoute 2 parametre a la fonction pour choisir le nb d'espace qui apparaisse entre le text et l'encadrement ( sp et li) ----------------------------- #include #include static const unsigned char LL ='|'; // FONCTION ENCADRE TEXTE // Encadre le text texte avec sp espace sur la ligne et li ligne en haut et en bas void EncadreTexte(char* texte,int sp,int li ) { int lg =strlen(texte)+2*sp; int i; char * str1 =( char*)malloc(lg+3); char *str2=( char*)malloc(sp); char * str3 =( char*)malloc(lg+3); str1[lg]='\0'; str2[sp]='\0'; memset (str1,'#', lg+2); memset (str2,' ', sp); memset (str3,' ', lg+2); str3[0]=LL;str3[lg+1]=LL;str3[lg+2]='\n'; printf ( "%s \n" , str1); for (i=0;i

Re : encadre un texte en c/c++ le 19/11/2007 12:40:56

titof3812
je renvoie c'est passe bizar #include #include static const unsigned char LL ='|'; // FONCTION ENCADRE TEXTE // Encadre le text texte avec sp espace sur la ligne et li ligne en haut et en bas void EncadreTexte(char* texte,int sp,int li ) { int lg =strlen(texte)+2*sp; int i; char * str1 =( char*)malloc(lg+3); char *str2=( char*)malloc(sp); char * str3 =( char*)malloc(lg+3); str1[lg]='\0'; str2[sp]='\0'; memset (str1,'#', lg+2); memset (str2,' ', sp); memset (str3,' ', lg+2); str3[0]=LL;str3[lg+1]=LL;str3[lg+2]='\n'; printf ( "%s \n" , str1); for (i=0;i

[Page 1 Page 2]
Classé sous : int, printf, for, tabl, encadre

Participer à cet échange

Pub



Appels d'offres

Dessins techniques
Budget : 60€
Animation Flash - Doma...
Budget : 370€
Application flash medi...
Budget : 1 000€

CalendriCode

Juillet 2008
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Boutique

Boutique de goodies CodeS-SourceS