Programmtion en C

besmakhr -  
sadektlili Messages postés 165 Statut Membre -
Bonjour,
je recherche la solution d'une problème en C

probleme:

détermine et affiche le mot le plus long dans une phrase donnée

remarque : j'utilise esclipse C
Configuration: Windows XP
Internet Explorer 6.0

2 réponses

  1. Wardog Messages postés 398 Statut Membre 159
     
    Bonjour,

    on va dire que les mots sont sépares par des espaces uniquement.

    void mputchar(char c)
    {
    write (1, &c, 1);
    }

    void afficher_mot(char *str)
    {
    while (*str != '\0' && *str != ' ')
    {
    mputchar(*str);
    str++;
    }

    }

    int retourne_la_position_du_plus_grand_mot(char *str)
    {

    int cr;
    int ctr;
    int plus_grand;
    int position;

    cr = 0;
    ctr = 0;
    plus_grand = 0;
    position = 0;

    while (str[cr] != '\0')
    {
    cr++;
    ctr++;
    if (str[cr] == ' ' || str[cr] == '\0')
    {
    cr++;
    if (ctr >= plus_grand)
    {
    plus_grand = ctr;
    position = cr;
    }
    ctr = 0;
    }

    cr++;
    }
    return (cr);
    }

    int main()
    {
    char *str = "Salut sa va bien"

    afficher_mot(str + retourne_la_position_du_plus_grand_mot(str));

    return (0);

    }


    Pas sûr que sa compile :p A essayer

    0
  2. sadektlili Messages postés 165 Statut Membre 4
     
    seek_mot(char *ligne,int long)
    {int i,j=0,indc_mot=0,long_mot=0;

    for(i=0;i<long;i++ ,j++)
    {
    if(ligne[i]==' ')
    {
    if( j>long_mot)
    {
    long_mot=j;
    indc_mot=ins_mot;
    j=0;
    }
    ins_mot=i;
    }

    for(i=0;i<long_mot;i++)
    {
    cprintf("%c",ligne[indc_mot+long_mot]);
    }

    test ca si tu trouve des problemes->abdeljelil87@hotmail.com
    0