From 27118aa411543bff89ba51463459f97aa810202c Mon Sep 17 00:00:00 2001 From: swayam khanduri <63970499+SWAYAMKHANDURI@users.noreply.github.com> Date: Sat, 7 Oct 2023 12:38:55 +0530 Subject: [PATCH] Create W7PHEw.c Signed-off-by: swayam khanduri <63970499+SWAYAMKHANDURI@users.noreply.github.com> --- rW5xWl/W7PHEw.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 rW5xWl/W7PHEw.c diff --git a/rW5xWl/W7PHEw.c b/rW5xWl/W7PHEw.c new file mode 100644 index 0000000..4efda9f --- /dev/null +++ b/rW5xWl/W7PHEw.c @@ -0,0 +1,40 @@ +#include +#include + +char str[100], sub[100]; //declaring str and char string +int count = 0, count1 = 0; + +void main() +{ + int l, l1, l2; + + printf("\nEnter a string : "); + scanf("%[^\n]s", str); + + l1 = strlen(str); + + printf("\nEnter a substring : "); + scanf(" %[^\n]s", sub); + + l2 = strlen(sub); + + for (int i = 0; i < l1;) + { + int j = 0; + count = 0; + while ((str[i] == sub[j])) + { + count++; + i++; + j++; + } + if (count == l2) + { + count1++; + count = 0; + } + else + i++; + } + printf("%s occurs %d times in %s", sub, count1, str); +}