Write interactive C programs to perform the following on strings:
(a) To find the length of a given string without using the string library functions.
(b) To compare two strings without using string library functions.
(c)To count the total number of vowels and consonants in a string and display the counts
separately.
I'd be happy to help you with these C programs! Below are the interactive C programs to achieve the tasks you mentioned:
#include <stdio.h>
// Function to find the length of a string
int findStringLength(const char *str) {
int length = 0;
while (*str != '\0') {
length++;
str++;
}
return length;
}
// Function to compare two strings
int compareStrings(const char *str1, const char *str2) {
while (*str1 != '\0' && *str2 != '\0') {
if (*str1 != *str2) {
return 0; // Strings are not equal
}
str1++;
str2++;
}
// Check if both strings have reached the end
return (*str1 == '\0' && *str2 == '\0');
}
// Function to count vowels and consonants in a string
void countVowelsAndConsonants(const char *str, int *vowels, int *consonants) {
*vowels = 0;
*consonants = 0;
while (*str != '\0') {
if (*str >= 'A' && *str <= 'Z') {
*str += 32; // Convert uppercase to lowercase
}
if (*str >= 'a' && *str <= 'z') {
if (*str == 'a' || *str == 'e' || *str == 'i' || *str == 'o' || *str == 'u') {
______ _________ ________ _____ _________ _______ _______ ____.
______ _______ _________ ______ ________ ________ ________ ___.
________ ________ ___ __________ ________ ______ ___.
_______ ________ ____ _________ ______ ___ ___ _____ _____ ___ _____ ______.
_______ ___ ____ _____ _______ __________ ________ ___.
________ ______ _________ _________ __________ _________ _______.
___ ________ _________ ________ _________ ___ _________ _________ _____ ___.
____ ______ ________ _____ _____ _____ _________ _______ ___ __________.
__________ ______ _____ ________ ______ ____ __________.
__________ ____ ________ ___ ______ __________ _______ ________.
_____ _______ ________ ______ _________.
_________ ________ _____ __________ ______ ___ ___ _____ _____ _________.
_____ _______ __________ _________ ______ _________ ________ ________ _________.
____ _______ ____ __________ __________ _____ ________ ____ ______ ___.
_____ ______ ________ _______ ____ ___ ____ ____ _______.
_________ _______ __________ _____ _________ __________ ______ ______.
____ ___ ______ __________ _____ ______ ___ _______.
_________ ____ _______ ________ __________ _______ _________ _____ _________.
__________ ____ ______ _______ _________ _____ _______ ___ _________.
__________ ___ ____ _________ _________ ____.
________ ________ _________ _____ _________ __________ ______ ________ __________ ______ ________.
_________ ___ __________ _________ _________.
____ _______ ______ _______ _______ ____ ______ ___ _______ ______.
_______ _______ __________ ______ ________ ______.
________ ___ _______ _____ ____ ___.
_______ _________ _____ ______ _____ ________ _______ __________ ______ ____.
________ _____ ______ __________ _____ ____ ______ ____ _______ _____.
___ __________ ______ _______ _______ ________.
_________ _____ __________ ______ __________ ___ _____ ________ _______.
________ ______ _________ ____ _______ _______ ______ __________ __________ ______.
__________ _________ _________ _____ ______ _______ _______ _______ __________ _________.
_______ _____ __________ ________ ________ _____ _________ ______ ________ _________.
__________ ____ ______ _______ _______ _____ _________ _____ _______.
______ ______ ______ _____ ________ _________ __________.
_______ ___ __________ _____ ______ _____ __________.
______ _________ ____ ___ __________ __________ _______ ________ ________.
_____ _____ __________ ________ ____ __________ _________ ____ ________ __________ ___.
_________ ____ _____ ____ _______ ______ ______ ________ _____ ______.
_________ ________ ________ ______ _______ __________ ___ _____.
_________ ______ _________ _________ ______ ____ __________ _____ __________ ___ ____ ___.
____ ________ _________ __________ _________ _________ ______ ______ _______ ____.
_________ _______ _______ _______ ________ _______.
_________ ______ _____ _______ _____ ______ _______ _____ ______ ____.
__________ ____ __________ _________ ________ ______ _______ ________ _____ __________.
____ _______ ____ _________ ____ ________ _______.
___ ____ __________ ____ ______ ______ ____ ____.
______ __________ _________ ___ ___ ______ _____ __________ __________ __________ _______ ____.
_______ ________ ____ _________ ____.
________ __________ __________ __________ ___ ________ ___ ______ _____ ________ _______ ________.
_____ _______ ________ ______ ______ _____ __________.
_______ ____ ____ ___ __________.
_______ ___ _____ __________ _________ __________ ___ ______ _______ ___.
___ __________ _________ _________ _____ ____ _____ ____ _____ __________.
______ ___ ___ ________ ____ _________ __________ _________.
___ ______ _______ __________ ______.
_______ ______ ________ ________ ____ _________ ___ _____ __________ ______ ____ _______.
_________ ___ ______ ____ ________ _____ ___ _________ _______.
____ _____ _____ _______ _______ _________ _______ _____ __________.
_______ ____ _______ ___ _________ _________.
________ ____ _____ _________ ________ ____ _______ __________.
_________ _____ ________ _____ ________ _________ ____ _____ _______ ___ _____ ___.
______ ____ ______ ______ _______ ________ ________ ___.
____ _______ _____ ______ _______ _________ ______ _______ __________ ____ _____.
_____ ________ _______ _______ ______ ____ __________ ____.
______ __________ ____ ______ ___ _________ ________ ________ _________ ___.
_______ __________ _____ _____ ________ __________ ____ _________ _______ ______ ______.
______ _______ ____ ___ __________ __________ __________ __________ ____ _______ _______ _______.
________ __________ ______ ______ _______ _______ ___ _______ _______ _______.
____ ________ ___ _____ ______ _____ ____ ________ _________ ________ _______.
_______ ____ ____ ________ _________ _______.
- Solved Assignments
- Study Notes
- Guess Papers
- Question Papers
✓ Unlock up to 60% of the answer
✓ No payment required