Forum Graph100

Forum Graph100

Vous n'êtes pas identifié.

Annonce

Bonjour et bienvenue sur le nouveau Forum Graph100 !
L'intégralité des données a été transférée sur un forum PunBB et tout les comptes sont fonctionnels avec le même nom d'utilisateur et mot de passe.
Un wiki est aussi disponible avec le même compte ! N'oubliez pas de remettre votre avatar, bon surf !
Pour plus d'informations, consultez ce post.

#1 06 Oct 2002 15:44:40

Julien
C++iste convaincu
Lieu: Waterloo (Be)
Date d'inscription: 29 May 2002
Messages: 1456
Site web

Passage par référence

Bon apparemment le passage par référence ( avec pointeur ) est aussi spécifique au c++, donc me revoila bien embêté:

J'ai un tableau texte[] de caracteres, et j'appelle une fonction writetext() qui va permettre a l'utilisateur d'écrire le contenu de ce tableau.
Seulement, comment je fais pour indiquer que c'est bien avec texte[] qu'il faut travailler et pas avec un autre tableau?  smile


Pensez à surveiller mes releases wink

Hors ligne

 

#2 06 Oct 2002 18:38:58

Julien
C++iste convaincu
Lieu: Waterloo (Be)
Date d'inscription: 29 May 2002
Messages: 1456
Site web

Re: Passage par référence

En fait je n'arrive pas a compiler ca:

Code:

#include "casio2b.h";
// le tableau de char alpha n'a pas été remis ici

int writetext(int x,int y,[color=red]unsigned char &texte[][/color],int n,int page,int couleur,int bg)
{
int i=0,j,key,type=0;
//type: 0 lettres, 1 chiffres
char c;
while (texte[i]!=99) i++;
    do    {        j=1;
    key=getch();            if (key==28 || key==75 || key==72 || key==77 || key==80) j=0;            if (type==0)    if (j)    if (!( (key<46||key>57) && (key<65||key>90) )) j=0;            else if (j) if (!(key<48||key>57)) j=0;            }
        while (j);
        if (key==28 || key==75 || key==72 || key==77 || key==80) return key;

        if (key!=83 && key!=56 && i!=n)
        {
        if (type==0)
            {
            c=key;

            if(key>=55 && key<=57) c+=22;
            if(key>=52 && key<=54) c+=28;
            if(key>=49 && key<=51) c+=36;
            if(key==48) c='Z';
            if(key==46) c=' ';
            }
        else c=key-48;
            drawdchar(x+5*(i+1),y,c,page,couleur,bg);
            texte[i]=c;
            i++;
            }
        if (key==83 && i!=0)
            {
            i--;
            drawdchar(x+5*(i+1),y,' ',page,couleur,bg);
            texte[i]=99;
            }
        if (key==56)
            {
            type++;
            if (type==2) type=0;
            }
     return 0;        }

void drawdchar(int x,int y, char c1, int page,int coul,int bg)  
{

    char c2;
    int i,j;
    if (c1>=48 && c1<=57) c2=c1-48;
    if (c1>=65 && c1<=90) c2=c1-55;
    if (c1==' ') c2=36;
    if (c1=='<') c2=37;
    if (c1=='>') c2=38;
    if (c1=='[') c2=39;
    if (c1==']') c2=40;
    if (c1==':') c2=41;
    if (c1=='-') c2=42;
    if (c1=='?') c2=43;
    if (c1=='.') c2=44;
    if (c1=='$') c2=45;
    if (c1=='=') c2=46;
    if (c1=='(') c2=47;
    if (c1==')') c2=48;
    if (c1=='{') c2=49;
    if (c1=='}') c2=50;
    if (c1=='/') c2=51;
    if (c1=='\') c2=52;
    if (c1=='_') c2=53;
    if (c1=='!') c2=54;
    if (c1=='ø') c2=55;
    if (c1==',') c2=56;
    if (c1==';') c2=57;
    if (c1=='+') c2=58;
    if (c1=='*') c2=59;
    if (c1=='@') c2=60;
    if (c1=='`') c2=61;

    for(i=0;i<5;i++) for(j=0;j<4;j++)
     {
      if (alpha[c2][i][j]==1) setPix(x+j,y+i,page,coul);
      else if(bg!=-1) setPix(x+j,y+i,page,bg);
     }
    }

void afftext(int x,int y,char st[],int page, int couleur,int bg )
    { int l;
    for(l=0;st[l]!='';l++) drawdchar(x+5*l,y,st[l],page,couleur,bg);}

void main()
{
int j;
[color=red]unsigned char texte[10]="cccccccccc";[/color]
clearpage(0);

j=writetext(1,5,[color=red]texte[/color],10,0,1,-1);

afftext(1,20,texte,0,1,-1);
if (j==28) afftext(1,30,"exe",0,1,-1);
if (j==75) afftext(1,30,"gauche",0,1,-1);
if (j==77) afftext(1,30,"droite",0,1,-1);
if (j==72) afftext(1,30,"haut",0,1,-1);
if (j==80) afftext(1,30,"bas",0,1,-1);
waitkey();
}

J'ai un probleme au niveau des pointeurs et du passage du tab texte[] vers la fonction writetext()...

Désolé de vous casser les pieds sans cesse, mais j'ai essayer pas mal de trucs sans aucun succès


Pensez à surveiller mes releases wink

Hors ligne

 

#3 07 Oct 2002 03:44:35

Azor
Le Coté Obscur De La G100
Lieu: glop glop!
Date d'inscription: 04 May 2002
Messages: 5479
Site web

Re: Passage par référence

Code:

#include "casio2b.h";
// le tableau de char alpha n'a pas été remis ici

int writetext(int x,int y,[color=red]unsigned char text[][/color],int n,int page,int couleur,int bg)
{
int i=0,j,key,type=0;
//type: 0 lettres, 1 chiffres
char c;
while (text[i]!=99) i++;
    do    {        j=1;
    key=getch();            if (key==28 || key==75 || key==72 || key==77 || key==80) j=0;            if (type==0)    if (j)    if (!( (key<46||key>57) && (key<65||key>90) )) j=0;            else if (j) if (!(key<48||key>57)) j=0;            }
        while (j);
        if (key==28 || key==75 || key==72 || key==77 || key==80) return key;

        if (key!=83 && key!=56 && i!=n)
        {
        if (type==0)
            {
            c=key;

            if(key>=55 && key<=57) c+=22;
            if(key>=52 && key<=54) c+=28;
            if(key>=49 && key<=51) c+=36;
            if(key==48 ) c='Z';
            if(key==46) c=' ';
            }
        else c=key-48;
            drawdchar(x+5*(i+1),y,c,page,couleur,bg);
            text[i]=c;
            i++;
            }
        if (key==83 && i!=0)
            {
            i--;
            drawdchar(x+5*(i+1),y,' ',page,couleur,bg);
            text[i]=99;
            }
        if (key==56)
            {
            type++;
            if (type==2) type=0;
            }
     return 0;        }

void drawdchar(int x,int y, char c1, int page,int coul,int bg)  
{

    char c2;
    int i,j;
    if (c1>=48 && c1<=57) c2=c1-48;
    if (c1>=65 && c1<=90) c2=c1-55;
    if (c1==' ') c2=36;
    if (c1=='<') c2=37;
    if (c1=='>') c2=38;
    if (c1=='[') c2=39;
    if (c1==']') c2=40;
    if (c1==':') c2=41;
    if (c1=='-') c2=42;
    if (c1=='?') c2=43;
    if (c1=='.') c2=44;
    if (c1=='$') c2=45;
    if (c1=='=') c2=46;
    if (c1=='(') c2=47;
    if (c1==')') c2=48;
    if (c1=='{') c2=49;
    if (c1=='}') c2=50;
    if (c1=='/') c2=51;
    if (c1=='\') c2=52;
    if (c1=='_') c2=53;
    if (c1=='!') c2=54;
    if (c1=='ø') c2=55;
    if (c1==',') c2=56;
    if (c1==';') c2=57;
    if (c1=='+') c2=58;
    if (c1=='*') c2=59;
    if (c1=='@') c2=60;
    if (c1=='`') c2=61;

    for(i=0;i<5;i++) for(j=0;j<4;j++)
     {
      if (alpha[c2][i][j]==1) setPix(x+j,y+i,page,coul);
      else if(bg!=-1) setPix(x+j,y+i,page,bg);
     }
    }

void afftext(int x,int y,char st[],int page, int couleur,int bg )
    { int l;
    for(l=0;st[l]!='';l++) drawdchar(x+5*l,y,st[l],page,couleur,bg);}

void main()
{
int j;
[color=red]unsigned char texte[]="cccccccccc";[/color]
clearpage(0);

j=writetext(1,5,[color=red]texte[/color],10,0,1,-1);

afftext(1,20,texte,0,1,-1);
if (j==28 ) afftext(1,30,"exe",0,1,-1);
if (j==75) afftext(1,30,"gauche",0,1,-1);
if (j==77) afftext(1,30,"droite",0,1,-1);
if (j==72) afftext(1,30,"haut",0,1,-1);
if (j==80) afftext(1,30,"bas",0,1,-1);
waitkey();
}

C soit &text, soit text[], ms po les 2 !!

voila, essaye maintenant ;-)


Anciennement X-thunder28
Cats shall rule teh world!

Hors ligne

 

#4 07 Oct 2002 13:10:26

Julien
C++iste convaincu
Lieu: Waterloo (Be)
Date d'inscription: 29 May 2002
Messages: 1456
Site web

Re: Passage par référence

Ben moi je veux bien mais ca ca va définir un tab texte[] et un tab text[] différents: donc les opérations sur text ne seront pas reproduites sur texte... si? sad


Pensez à surveiller mes releases wink

Hors ligne

 

#5 08 Oct 2002 06:35:10

Azor
Le Coté Obscur De La G100
Lieu: glop glop!
Date d'inscription: 04 May 2002
Messages: 5479
Site web

Re: Passage par référence

sisi t' inkiète, ca marche, c ce ke j' utilise !!!


Anciennement X-thunder28
Cats shall rule teh world!

Hors ligne

 

Pied de page des forums

Propulsé par PunBB
© Copyright 2002–2005 Rickard Andersson
Traduction par punbb.fr