Skip to content
This repository has been archived by the owner on Oct 7, 2023. It is now read-only.

Create W7PHEw.c #1613

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions rW5xWl/W7PHEw.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <stdio.h>
#include <string.h>

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);
}