Bonjour,
j'ai quelques petits problèmes à la compilation de mon programme.
Dans le main je veux construire un tableau en demandant sa taille.
Je veux ensuite trier son contenu en faisant appel à une fonction ayant comme paramètre ce tableau.
Le problème est qu'à la compilation Visual C++ me donne toutes ces erreurs:
C:\Disque D\Poly\algorithmique\tp1\main.c(15) : error C2143: syntax error : missing ';' before 'type'
C:\Disque D\Poly\algorithmique\tp1\main.c(22) : error C2065: 'tab' : undeclared identifier
C:\Disque D\Poly\algorithmique\tp1\main.c(22) : error C2109: subscript requires array or pointer type
C:\Disque D\Poly\algorithmique\tp1\main.c(22) : error C2106: '=' : left operand must be l-value
C:\Disque D\Poly\algorithmique\tp1\main.c(27) : error C2109: subscript requires array or pointer type
C:\Disque D\Poly\algorithmique\tp1\main.c(29) : warning C4047: 'function' : 'int *' differs in levels of indirection from 'int '
C:\Disque D\Poly\algorithmique\tp1\main.c(29) : warning C4024: 'bulle' : different types for formal and actual parameter 1
C:\Disque D\Poly\algorithmique\tp1\main.c(34) : warning C4028: formal parameter 1 different from declaration
C:\Disque D\Poly\algorithmique\tp1\main.c(44) : error C2109: subscript requires array or pointer type
C:\Disque D\Poly\algorithmique\tp1\main.c(44) : error C2109: subscript requires array or pointer type
C:\Disque D\Poly\algorithmique\tp1\main.c(47) : error C2109: subscript requires array or pointer type
C:\Disque D\Poly\algorithmique\tp1\main.c(48) : error C2109: subscript requires array or pointer type
C:\Disque D\Poly\algorithmique\tp1\main.c(48) : error C2109: subscript requires array or pointer type
C:\Disque D\Poly\algorithmique\tp1\main.c(48) : error C2106: '=' : left operand must be l-value
C:\Disque D\Poly\algorithmique\tp1\main.c(49) : error C2109: subscript requires array or pointer type
C:\Disque D\Poly\algorithmique\tp1\main.c(49) : error C2106: '=' : left operand must be l-value
C:\Disque D\Poly\algorithmique\tp1\main.c(58) : error C2109: subscript requires array or pointer type
Error executing cl.exe.
voici mon code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
void bulle(int tab[],int max);
void main(void)
{
int max;
int i;
printf("\n Entrer la longueur du tableau");
scanf("%d",&max);
int tab[max];
printf("\n Entrer la longueur du tableau");
scanf("%d",&max);
srand( (unsigned)time( NULL ));
for( i = 0;i < max;i++ )
tab[i]=rand();
//Présentation du tableau
printf("\n **** Tableau de depart **** \n");
for(i=0;i<max;i++)
printf("%d \n",tab[i]);
bulle(tab,max);
}
void bulle(int tab,int max)
{
int i;
int ok;
int temp;
do
{
ok=1;
for(i=1;i<max;i++)
{
if(tab[i-1]>tab[i])
{
ok=0;
temp=tab[i-1];
tab[i-1]=tab[i];
tab[i]=temp;
}
}
}while(!ok);
//Résultat final
printf("\n **** Tableau final **** \n");
for(i=0;i<max;i++)
printf("%d \n",tab[i]);
printf("\n");
}
Merci pour votre aide, j'en ai bien besoin 