- /**********************/
- /* El Antri Abdellah */
- /* 26 janvier 2005 */
- /* Sous liscence GNU */
- /**********************/
-
- #include<stdio.h>
- #include<conio.h>
- #include<string.h>
-
- char text[200],motif[200];
- long long_text,long_motif,i,j,k,nbr_occurence;
- int trouver;
-
- void main()
- {
- clrscr();
- k = 0;
- nbr_occurence = 0;
- printf("\n\r Tapper une text sans espace:");
- scanf("%s",text);
- printf("\n\r Tapper un mot:");
- scanf("%s",motif);
- long_text = strlen(text);
- long_motif = strlen(motif);
-
- while(k <= long_text - long_motif )
- {
- trouver = 0;
- j = k;
- i = 0;
- while (text[j] == motif[i] && !trouver)
- if(i == long_motif - 1)
- {
- trouver = 1;
- nbr_occurence = nbr_occurence + 1;
- i = 0;
- }
- else
- {
- i = i + 1;
- j = j + 1;
- }
- k = k + 1;
- }
- printf(" Le nombre d'occurence de %s dans %s est: %ld",motif,text,nbr_occurence);
- getch();
- }
/**********************/
/* El Antri Abdellah */
/* 26 janvier 2005 */
/* Sous liscence GNU */
/**********************/
#include<stdio.h>
#include<conio.h>
#include<string.h>
char text[200],motif[200];
long long_text,long_motif,i,j,k,nbr_occurence;
int trouver;
void main()
{
clrscr();
k = 0;
nbr_occurence = 0;
printf("\n\r Tapper une text sans espace:");
scanf("%s",text);
printf("\n\r Tapper un mot:");
scanf("%s",motif);
long_text = strlen(text);
long_motif = strlen(motif);
while(k <= long_text - long_motif )
{
trouver = 0;
j = k;
i = 0;
while (text[j] == motif[i] && !trouver)
if(i == long_motif - 1)
{
trouver = 1;
nbr_occurence = nbr_occurence + 1;
i = 0;
}
else
{
i = i + 1;
j = j + 1;
}
k = k + 1;
}
printf(" Le nombre d'occurence de %s dans %s est: %ld",motif,text,nbr_occurence);
getch();
}