Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int dlugosc(char*lan);
- int sprawdz(char*tekst, char*wzor);
- int* sprawdz_w(char* tekst,char*wzor,int* ilosc);
- int main(){
- char slowo[50];
- char wzorzec[50];
- printf("Podaj lancuch: ");
- fflush(stdin);
- scanf("%49[^\n]s",slowo);
- printf("Dlugosc slowa to to: %d\n",dlugosc(slowo));
- printf("Podaj wzorzec: ");
- fflush(stdin);
- scanf("%49[^\n]s",wzorzec);
- printf("Czy sie zgadza: %d\n",sprawdz(slowo,wzorzec));
- getch();
- }
- int dlugosc(char*lan){
- int i=0;
- while(*(lan+i)!='\0'){
- i++;
- }
- return i;
- }
- int sprawdz(char*tekst, char*wzor){
- int i,dt=dlugosc(tekst),dw=dlugosc(wzor),j,tak=0;
- for(i=0;i<dt-dw+1;i++){
- if(*(tekst+i)==*wzor){ tak=1;
- for(j=0;j<dw;j++){
- if(*(tekst+i+j)!=*(wzor+j)){
- tak=0; }
- }
- }
- }
- return tak;
- }
- int* sprawdz_w(char* tekst, char* wzor, int* ilosc)
- {
- int* tab=NULL;
- int i=0, j=0, dt=dlugosc(tekst), dw=dlugosc(wzor);
- *ilosc=0;
- for(i=0; i<dt-dw+1; i++)
- {
- for(j=0; j<dw; j++)
- {
- if(tekst[i+j]!=wzor[j])
- {
- break;
- }
- }
- if(j==dw)
- {
- tab=(int*)realloc(tab,(*ilosc+1)*sizeof(int));
- *(tab+*ilosc)=i;
- (*ilosc)++;
- }
- }
- return tab;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement