Programmtion en C
Fermé
besmakhr
-
28 déc. 2008 à 15:57
sadektlili Messages postés 139 Date d'inscription mardi 16 décembre 2008 Statut Membre Dernière intervention 3 avril 2010 - 28 déc. 2008 à 16:39
sadektlili Messages postés 139 Date d'inscription mardi 16 décembre 2008 Statut Membre Dernière intervention 3 avril 2010 - 28 déc. 2008 à 16:39
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
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
2 réponses
Wardog
Messages postés
389
Date d'inscription
mercredi 5 octobre 2005
Statut
Membre
Dernière intervention
17 octobre 2009
159
28 déc. 2008 à 16:14
28 déc. 2008 à 16:14
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
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
sadektlili
Messages postés
139
Date d'inscription
mardi 16 décembre 2008
Statut
Membre
Dernière intervention
3 avril 2010
4
28 déc. 2008 à 16:39
28 déc. 2008 à 16:39
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
{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