Lab5 Part 1 Count the occurrences of a single character in a string. Example output: $ ./lab02 foobar o $ ./lab02 foobar invalid arguments Part 2 Count the occurrences of an N-character string in another string. Example output: $ ./lab02 abbabb bb 2 $ ./lab02 abbabb bc You may use the C library function strstr() if you wish. char *strstr(char *a, char *b) returns a pointer to the first occurrence of b if b occurs in a, or NULL if b does not occur in a
In C programing, (not C++ or C#) how can I make appropriate output on the instruction?
#include <stdio.h>
#include <string.h>
int part1(char theVlue[],char theChVal) {
int e, thecnt;
thecnt = 0;
for(e = 0; e <= strlen(theVlue); e++)
{
if(theVlue[e] == theChVal)
{
thecnt++;
}
}
printf("\n %d ", thecnt);
}
int part2(char theVlue[], char theSubVlue[]) {
int e, f, strLnth, highLen, lowLen,cntLen,cntLen1=0;
highLen = strlen(theVlue);
lowLen = strlen(theSubVlue);
for (e = 0; e < highLen;) {
f = 0;
cntLen = 0;
while ((theVlue[e] == theSubVlue[f])) {
cntLen++;
e++;
f++;
}
if (cntLen == lowLen)
{
cntLen1++;
cntLen = 0;
}
else
e++;
}
printf("\n %d", cntLen1);
}
int main() {
char theVlue[10]="afaan";
char str1[10]="aa";
char theChVal='a';
part1(theVlue,theChVal);
part2(theVlue,str1);
return 0;
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 6 images