#include <stdio.h>
// (a) Function to return length
of string using a for loop
int length(char str[]){
int count = 0;
for(int
i = 0; str[i] != '\0'; i++)
count++;
return count;
}
// (b) Function to check if word
is present in string using for loop
// Return 1 if word is present
otherwise 0
int find(char str[], char word[]){
int strLength = length(str); // Find length of string
int wordLength = length(word); // Find length of word
int isFound = 1;
for(int
i = 0; i < strLength -
wordLength; i++){
isFound =
1;
for(int
j = 0; j < wordLength;
j++){
if(str[i
+ j] != word[j]){
isFound
= 0;
break;
}
}
if(isFound)
return
1;
}
return 0;
}
int main(){
char str[] = "I love
programming in C";
char word1[] = "programming";
char word2[] = "C++";
printf("Length of string \"%s\" is %d\n", str,
length(str));
if(find(str, word1))
printf("\"%s\" found in string\n", word1);
else
printf("\"%s\" NOT found in string\n",
word1);
if(find(str, word2))
printf("\"%s\" found in string\n", word2);
else
printf("\"%s\" NOT found in string\n",
word2);
return 0;
}