⚔️Ex 3 (Linux)

#include <stdio.h>
#include <string.h>
int main()
{
char buffer[20];
char sub_buf[10];
printf("Enter strings: ");
gets(buffer);
printf("Enter sub-strings: ");
gets(sub_buf);
int k = 0, count = 0, store = 0, i = 0;
while(i < strlen(buffer)){
if(buffer[i] == sub_buf[k]){
count++;
if(count == strlen(sub_buf)){
store = i;
break;
}
k++;
}else{
count = 0;
}
i++;
}
if(count == strlen(sub_buf)){
printf("Location: [%d]", store - k);
}else{
printf("Location: [none]");
}
return 0;
}
Last updated