Home > Blockchain >  error: expected ‘;’, ‘,’ or ‘)’ before ‘{’ token
error: expected ‘;’, ‘,’ or ‘)’ before ‘{’ token

Time:09-16

I'm trying to compile with gcc a code which create a list of random integers, and sort it. But i'm getting these errors :

main.c:8:1: error: expected ‘;’, ‘,’ or ‘)’ before ‘{’ token
    8 | {
      | ^
tri.c:8:1: error: expected ‘;’, ‘,’ or ‘)’ before ‘{’ token
    8 | {
      | ^

My first file main.c contains :

#include <stdio.h>
#include <stdlib.h>
#include "tri.h"
#include "annexe.h"


int main(void)
{
    int *T;
    int n,d,k;
    char e;
    do
    {
        Saisir_n1(n);
        trait();
        T=CreaTablD(n);
        AffichageD(T,n);
        do
        {
            printf("\nChoisir entre le tri par insertion (1) et le tri par selection (2) : ");
            scanf("%d",&d);
        }while(d!=1 && d!=2);
        do
        {
            printf("\nChoisir entre un tri par ordre décroissant (d) et un tri par ordre croissant (c) : ");
            scanf("%c", &e);
        }while(e!='c' && e!='d');
        trait();
        if (d==1)
            Tri_Insertion(T,n,e);
        else
            Tri_Selection(T,n,e);
        AffichageD(T,n);
        free(T);
        do
        {
            printf("\nVoulez-vous recommencer ?\nOui(1)\tNon(0) : ");
            scanf("%d"&k);
        }while(k!=1 && k!=0);
    }while(k==1);
    return(0);
}

And my second file tri.c contains :

#include <stdio.h>
#include <stdlib.h>
#include "annexe.h"



void Tri_Insertion(int *T, int n, char choix)
{
    int cle,j;
    if (choix!='c' && choix!='d')
    {
        printf("\nErreur dans le choix des paramètres\n");
        return;
    }
    for (int i=1; i<n;i  )
    {
        cle=*(T i);
        j=i-1
        if (choix=='c')
        {
            while (j>0 && *(T j)>cle)
            {
                *(T j 1)=*(T i);
                j--;
            }
        }
        else 
        {
            while (j>0 && *(T j)<cle)
                {
                    *(T j 1)=*(T i);
                    j--;
                }
        }
        *(T j 1)=cle;
    }
}

void Tri_Selection(int *T, int n, char choix)
{
    int ie,e;
    if (choix!='c' && choix!='d')
    {
        printf("\nErreur dans le choix des paramètres\n");
        return;
    }
    if (choix=='c')
    {
        for (int i=0; i<n; i  )
        {
            PlusPetitD(T,ie,e,0,n);
            if (ie!=i)
            {
                permutationD(T i,T ie);
            }
        }
    }
    else
    {
        for (int i=0; i<n; i  )
        {
            PlusGrandD(T,ie,e,0,n);
            if (ie!=i)
            {
                permutationD(T i,T ie);
            }
        }
    }
}

annexe.c is a file where I'm pretty sure there is no problem because it works with another files. I checked all the "}" and "{", all the ";" and no one is missing.

Thank you for your help.

CodePudding user response:

Almost certain it's in your Tri_Insertion() function - you have the following unterminated line which is probably throwing a compiler error (it seems to be about line 8 of your tri.c file:

    j=i-1
    if (choix=='c')
    {

which should instead be:

    j=i-1;
    if (choix=='c')
    {

CodePudding user response:

Your second file is called tri.c , but in main you include it as a header file #include "tri.h" . Is that correct?

  •  Tags:  
  • c
  • Related