tomalille
Messages postés52Date d'inscriptionjeudi 16 juin 2005StatutMembreDernière intervention 5 juin 2007
-
9 sept. 2005 à 05:41
tomalille
Messages postés52Date d'inscriptionjeudi 16 juin 2005StatutMembreDernière intervention 5 juin 2007
-
9 sept. 2005 à 13:24
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.
cs_louis14
Messages postés793Date d'inscriptionmardi 8 juillet 2003StatutMembreDernière intervention10 février 20218 9 sept. 2005 à 09:09
bonjour,
voilà le code corrigé
il faut faire des allocations dynamiques des variables ou bien une constante avec une valeur élevée. de plus il faut déclarer les variables au début.
bonne programmation
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
void bulle(int* tab,int max);
void main(void)
{
int max =0;//initialisé les valeurs
int i = 0;
int* tab = NULL;
printf("coucou\n");
printf("\n Entrer la longueur du tableau");
scanf("%d",&max);
//int tab[max];//il faut allouer de la mémoire ou déclarer une connstate MAXIMUM
tab = (int*)malloc(max*sizeof(int));
//pourquoi 2fois?
//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);
free(tab);
}
void bulle(int* tab,int max)
{
int i =0;
int ok = 1;
int temp = 0;