Write C programs named mystring.h and mystring.c, containing the headers and implementations of the following functions.
mystring.h
#include <stdio.h>
int letter_count(char *);
void lower_case(char *);
int word_count(char *);
void trim(char *);
mystring.c
#include "mystring.h"
int letter_count(char *s)
{
// your implementation
}
void lower_case(char *s) {
// your implementation
}
int word_count(char *s) {
// your implementation
}
void trim(char *s) {
// your implementation
}
Use the provided main function to test the above functions.
#include "mystring.h"
int main(int argc, char* args[]) {
setbuf(stdout, NULL);
char str[100] = " This Is a Test ";
printf("\nInput string: \"%s\"", str);
printf("\nLetter count:%d", letter_count(str));
printf("\nWord count:%d", word_count(str));
trim(str);
printf("\nAfter trimming:\"%s\"", str);
lower_case(str);
printf("\nAfter lower case:\"%s\"", str);
return 0;
}
output should look like this:
Input string: " This Is a Test "
Letter count:11
Word count:4
After trimming:"This Is a Test"
After lower case:"this is a test"
Here is the solution to above problem. I am using string.h and ctype.h for finding stringlength and checking if letter is an alphabet or converting to lowercase. Please refer to the code screenshot for indentation
HERE IS THE C CODE FOR PROGRAM
#include "mystring.h"
#include<stdio.h>
#include<string.h>
#include <ctype.h>
int letter_count(char *s)
{
//finding string length
int length= strlen(s);
int i;
int count=0;
for(i=0;i<length;++i)
{ //checking if it is alphabet
if(isalpha(s[i]))
count++; //incrementing count
}
return count;
}
void lower_case(char *s) {
// stringlength using string.h library
int length= strlen(s);
int i;
for(i=0;i<length;++i)
{
//using to toLower to convert to
lower case
s[i]=tolower(s[i]);
}
}
//counting the number of words
int word_count(char *s) {
// your implementation
int length= strlen(s);
int i;
int count=0;
for(i=0;i<length-1;++i)
{
//if counting for word if two
consequtive space are not present
if (s[i] == ' ' && s[i+1]
!= ' ')
{
count++;
}
}
return count;
}
void trim(char *s) {
// your implementation
int length= strlen(s);
char * temp = (char
*)malloc(sizeof(char)*length);
int i=0;
int j=0;
int count=0;
//removing prefix white spaces
while(s[i]==' ')
i++;
//removing unnecessary spaces in between
while(i<length-1)
{
if(!(s[i]==' '&& s[i+1]=='
') )
{
temp[j]=s[i];
j++;
}
i++;
}
temp[j]='\0';
//copying temp to original string
for(i=0;i<strlen(temp);++i)
{
s[i]=temp[i];
}
s[i]='\0';
}
int main(int argc, char* args[]) {
setbuf(stdout, NULL);
char str[100] = " This Is a Test ";
printf("\nInput string: \"%s\"", str);
printf("\nLetter count:%d", letter_count(str));
printf("\nWord count:%d", word_count(str));
trim(str);
printf("\nAfter trimming:\"%s\"", str);
lower_case(str);
printf("\nAfter lower case:\"%s\"", str);
return 0;
}
OUTPUT OF CODE

SCREENSHOT OF CODE



Write C programs named mystring.h and mystring.c, containing the headers and implementations of the following functions....
In C programming Write the implementation for the three functions described below. The functions are called from the provided main function. You may need to define additional “helper” functions to solve the problem efficiently. Write a print_string function that prints the characters in a string to screen on- by-one. Write a is_identical function that compares if two strings are identical. The functions is required to be case insensitive. Return 0 if the two strings are not identical and 1 if...
C programming Write the implementation for the three functions described below. The functions are called from the provided main function. You may need to define additional “helper” functions to solve the problem efficiently. a) Write a print_string function that prints the characters in a string to screen on- by-one. b) Write a is_identical function that compares if two strings are identical. The functions is required to be case insensitive. Return 0 if the two strings are not identical and 1...
Please write code in C++ and include all headers not bits/stdc: 17.10 (Occurrences of a specified character in a string) Write a recursive function that finds the number of occurrences of a specified letter in a string using the following function header. int count(const string& s, char a) For example, count("Welcome", 'e') returns 2. Write a test program that prompts the user to enter a string and a character, and displays the number of occurrences for the character in the...
USE C programming (pls label which file is libcipher.h and libcipher.c) Q4) A shift cipher is one of the simplest encryption techniques in the field of cryptography. It is a cipher in which each letter in a plain text message is replaced by a letter some fixed number of positions up the alphabet (i.e., by right shifting the alphabetic characters in the plain text message). For example, with a right shift of 2, ’A’ is replaced by ’C’, ’B’ is...
Programs 1. String Utilities In this exercise you will implement several utility functions involving strings. You will place all of your function prototypes in a header file named string utils.h and all of your function definitions in a source file named string utils.c. You should implement your own main test driver program to test your functions, but you need not hand it in. a. void addChar(char *str, char c, int n) - this function should add a char c at...
The following code is a C Program that is written for encrypting
and decrypting a string. provide a full explanation of the working
flow of the program.
#include <stdio.h> int main() { int i, x; char str[100]; printf("\n Please enter a valid string: \t"); gets (str); printf ("\n Please choose one of the following options: \n"); printf ("1 = Encrypt the given string. \n"); printf("2 = Decrypt the entered string. \n"); scanf("%d",&x); // using switch case statements switch (x) {...
Write a function that can return the length of a string in C language. Please leave comments to explain the code and verify that it runs properly... Example: Input String: China The length of the string is 5. #include <stdio.h> int length(char * p) { /write your code here } main(){ int len; char str[20]; printf("Input string:"); scanf("%s", str); len = length(str); printf("The length of string is %d. ", len); getchar(); ...
You have to clearly define what each if statement is doing in both programs. #include <stdio.h> static unsigned char count = 31; void callMe ( char ch ) { if ( ch == 'U' || ch == 'u') { if ( count > 15 ) count -= 16; printf ( "count = %d \n", count ) ; return; } if ( ch == 'A' || ch == 'a') { if ( count % 2 == 1) count -= 1; printf...
2. Pointer arithmetic: a) Write a printString function that prints a string (char-by-char) using pointer arithmetics and dereferencing. b) Write a function “void computeMinMax(double arr[], int length, double * min, double * max)” that finds the minimum and the maximum values in an array and stores the result in min and max. You are only allowed to use a single for loop in the function (no while loops). Find both the min and the max using the same for loop....
Write the following program in C Language using standard library
functions.
/*Implement the Find function, called in the program below. This function receives two strings, and looks for the first occurrence of the second string in the first string, returning the number of characters it is in, relative to the beginning of the first string. If not, returns -1. In the program, a string with two news headlines is given, and the sub-strings "iPad" and "Huawei” are searched for, having...