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
Max Function
Statistical function is of many categories. One of them is a MAX function. The MAX function returns the largest value from the list of arguments passed to it. MAX function always ignores the empty cells when performing the calculation.
Power Function
A power function is a type of single-term function. Its definition states that it is a variable containing a base value raised to a constant value acting as an exponent. This variable may also have a coefficient. For instance, the area of a circle can be given as:
In C
#include <stdio.h>
#include <string.h>
int part1(count char str[],int c)
{
int i;
int count = 0;
for(i = 0; str[i] != '0'; i++)
if(str[i] == c)
count++;
return(count);
}
int part2(count char str[], int c)
{
int a;
int count = 0;
for(a = 0; str[a] != '0'; i++)
if(str[a] == c)
count++;
return(count);
}
int main(int argc, char **argv){
char *needle = argv[2];
if(strlen(needle) == 1);{
count = part1(c);
if(strlen(needle) == 1);{
count = part1(c);
else{
printf("invalid arguments");
}
printf(strrchr(strsep, char[c]));
return 0;
}
}
}
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 3 images