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

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

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;

}

@vlab02 lab02-
@vlab02 lab02-
@vlab02 lab02-
J$ micro lab02.c
J$ gcc -g -o lab02 lab02.c
J$ ./lab02 ki i
3
@vlab02 lab02-
I$ ./lab02 foobar o
3
1[
@vlab02 lab02
i$ ./lab02 foobar
3
1[
@vlab02 lab02-
I$ ./lab02 abbabb bb
3
1
@vlab02 lab02-|
i$ ./lab02 abbabb bc
3
@vlab02 lab02
$ ./lab02 abbabb bc
3
1
@vlab02 lab02-|
1$ ./lab02 abbabb bc
Transcribed Image Text:@vlab02 lab02- @vlab02 lab02- @vlab02 lab02- J$ micro lab02.c J$ gcc -g -o lab02 lab02.c J$ ./lab02 ki i 3 @vlab02 lab02- I$ ./lab02 foobar o 3 1[ @vlab02 lab02 i$ ./lab02 foobar 3 1[ @vlab02 lab02- I$ ./lab02 abbabb bb 3 1 @vlab02 lab02-| i$ ./lab02 abbabb bc 3 @vlab02 lab02 $ ./lab02 abbabb bc 3 1 @vlab02 lab02-| 1$ ./lab02 abbabb bc
Lab5
Part 1
Count the occurrences of a single character in a string. Example output:
$ ./lab02 foobar o
2
$ ./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
Transcribed Image Text:Lab5 Part 1 Count the occurrences of a single character in a string. Example output: $ ./lab02 foobar o 2 $ ./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
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 6 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY