#include <stdio.h>
#include <string.h>
#include <alloc.h>
#include <conio.h>
void timchuoi(char *source, char *substr, int *k)
{
char *stmp, *dtmp, *found;
stmp = strlwr(strdup(source)); // Ham strlwr co the thay bang ham strupr
dtmp = strlwr(strdup(substr));
found = strstr(stmp, dtmp);
if (found)
*k = found - stmp;
else
*k = -1;
free(stmp);
free(dtmp);
}
void main()
{
char source[255], substr[50];
int k;
printf("
Nhap chuoi nguon : ");
gets(source);
printf("
Nhap chuoi tim kiem : ");
gets(substr);
timchuoi(source, substr, &k);
if (k != -1)
printf("
Chuoi tim thay tai vi tri : %d", k);
else
printf("
Khong tim thay chuoi da cho");
getch();
}
Bạn đang đọc truyện trên: Truyen4U.Com