Utiliser les pointeurs pour les tableaux

Résolu/Fermé
yadhus Messages postés 33 Date d'inscription dimanche 17 février 2008 Statut Membre Dernière intervention 16 mars 2009 - 5 mars 2008 à 17:40
dekker Messages postés 371 Date d'inscription samedi 5 janvier 2008 Statut Membre Dernière intervention 27 octobre 2009 - 5 mars 2008 à 17:55
Bonjour,
J'ai des problèmes pour saisir un tableau et l'afficher à l'aide des pointeurs; Bref voici le code source que j'ai essayé mais ça ne marche pas........


#include <stdio.h>



typedef char * string;



int saisie_tab (int *p, string mess, int N) {

int *pdeb,*pfin;
int T[10];
pdeb=&T[0];
pfin=&T[N];
for (p=pdeb-1;p<pfin-1;p++)
{
puts (mess);
scanf ("%d", *p);
}
return *p;
}





void affiche_tab (int *p, int N) {

int *pdeb,*pfin,T[10];
pdeb=&T[0];
pfin=&T[N];
for (p=pdeb-1;p<pfin-1;p++)
{
printf ("\t%d\t|", p);
}
}


int main () {

int *t;
int N=10;
string mess;
gets (mess);
saisie_tab (t,mess,N);
printf ("Voici votre tableau\n");
affiche_tab (t,N);



return 0;
}


Merci d'avance
A voir également:

2 réponses

dekker Messages postés 371 Date d'inscription samedi 5 janvier 2008 Statut Membre Dernière intervention 27 octobre 2009 12
5 mars 2008 à 17:47
tu te galere la vie je pense

atta je reflechie a ton problome ;)

je te rep dans 30 minute ^^

tu a pas forcement besion des pointeur tu peu ressoudre sa avec un compteur ( pour avoir l'indice du tableau que tu passe en refence dans tes fonction " variable globale" )

je te fait un code dans 30 minute ;)
0
dekker Messages postés 371 Date d'inscription samedi 5 janvier 2008 Statut Membre Dernière intervention 27 octobre 2009 12
5 mars 2008 à 17:55
tien j ai retrouver un de mes TP sur les tableau si tu veut plus d'info , paularch79@hotmail.com je suis en 1er IRIS


#include <iostream.h>

#include <stdlib.h>

#include <time.h>

#include <stdio.h>







void random(int tab[], int n)



{

int nb;



srand( time(0));



for (int cpt=0; cpt<n ;cpt++)



{

nb=(rand()%100);

tab[cpt]=nb;

}

}





void afficher(int tab[], int n)



{

for ( int i=0;i<n;i++)

cout<<tab[i]<<" ";



}









void valmanu (int tab[], int n)

{

int a;



for (int indice=0;indice<n;indice++)





{

cout<<"vous avez rentrer "<< indice<<" chiffre"<<endl;

cin>>a;

tab[indice]=a;

}

}









void totaltab (int tab[],int n, int &total)

{



for(int indice=0;indice<n;indice++)



{

total=total+tab[indice];

}



}



void moyentab ( int tab [],int n,int total, float &moyenne )

{

moyenne=(total/(float)10);

}









void valmax (int tab [],int n,int &max)

{

max=tab[0];



for (int indice=0;indice<n;indice++)

{

if ( tab[indice]>max)

max=tab[indice];

}

}





void valmin (int tab [],int n,int &min)

{

min=tab[0];



for (int indice=0;indice<n;indice++)

{

if ( tab[indice]<min)

min=tab[indice];

}

}







int main()



{



const int NB=10;

int tab[NB];

int total=0;

float moyenne;

int max ;

int min;

int choix;







cout<<"tableau aleatoir tapez 1 "<<endl;



cout<<"tableau manuel tapez 2"<<endl;



cout<<"une autre touche pour quitter"<<endl;



cin>> choix;



switch (choix)

{

case 1:

random(tab, NB);

afficher(tab, NB);



cout<<endl;



totaltab (tab, NB ,total );

cout<<"la somme est egale a "<<total<<endl;



moyentab ( tab, NB, total, moyenne );

cout<<"la moyenne est " <<moyenne<<endl ;



valmax ( tab , NB, max);

cout<<"le max est " <<max<<endl;



valmin ( tab , NB, min);

cout <<"le min est " <<min<<endl;





break;



case 2 :

valmanu (tab, NB) ;



afficher(tab, NB);



cout<<endl;



moyentab ( tab, NB, total, moyenne );

cout<<"la moyenne est " <<moyenne<<endl ;



valmax ( tab , NB, max);

cout<<"le max est " <<max<<endl;



valmin ( tab , NB, min);

cout <<"le min est " <<min<<endl;

break;



default: cout<< " quitter " ;



}
0