Question
Using Pointers,
- Write the character-counting function
- Write the string-concatenation program
Answer :
Word Count : 377
_________ _______ ______ ___ ____ __________ ______ __________.
________ ___ ________ _______ __________ ________ __________ ______ ______ _______ ______ __________.
_______ _____ ________ _____ _____.
________ ______ ______ ________ ___ ____.
___ ___ _____ ____ __________ _____ ______ ____ _________ ___ ________.
_________ ________ ____ _________ _________ ____ _______ ____ ____ _______.
____ __________ _____ ________ ________ _____ ____ __________ _____ ____ __________ _______.
____ _________ _____ ____ __________ ______ _____ _________ ______ ___ _____.
_________ ____ _____ _________ ________ ______ ________ __________ ________ _______ ______ _____.
_______ __________ _________ _______ ___ ___ __________ ________ ______.
_____ ________ ________ _____ _______ ______ ________ _____.
_____ ______ ________ __________ __________ ______ ______ _______ ____ ______ _________.
________ ____ ______ ________ _________ ________ ________ _____ __________ _______.
_____ ____ ________ ______ ____ __________ ________ ________ ______ ___ ________ _____.
______ ________ __________ ___ __________ ______ ______ ___ ________ ___.
___ ________ _____ _____ ___ _______ ________ ___.
_________ _____ ____ ________ ___ _________ ___ __________.
_____ _________ _______ _________ ____ ________ ______ ________.
__________ ___ _______ ________ ___.
______ _____ ________ ___ ____ ______ ______ ____ ______.
______ ________ _________ ____ __________ ___ ______.
___ ______ ________ ______ ___ ______ _________ ________.
______ __________ _________ ________ ________ ______.
________ _________ __________ _________ ______ _______ __________ ____ ____ ______ ________.
_________ _______ ________ ______ __________ ______ _______ _________ ________ _________ _________.
_____ ______ _______ ___ ____ ______.
Skip in 10
Character-Counting Function:
To write a function that counts the occurrence of a specific character in a string using pointers, we can iterate through the string and compare each character with the given one.
Here’s the code to count the occurrences of a character in a string:
#include <stdio.h> int count_characters(const char *str, char ch) { int count = 0; // Loop through the string until the null-terminator while (*str != '\0') { if (*str == ch) { count++; } str++; // Move to the next character in the string } return count; } int main() { const char *str = "programming"; char ch = 'g'; int result = count_characters(str, ch); printf("The character '%c' appears %d times.\n", ch, result); return 0; } Explanation:
- We define the
count_charactersfunction that takes a string (str) and a character (ch) as parameters. - The pointer
________ ___ ________ _______ __________ ________ __________ ______ ______ _______ ______ __________.
_______ _____ ________ _____ _____.
________ ______ ______ ________ ___ ____.
___ ___ _____ ____ __________ _____ ______ ____ _________ ___ ________.
_________ ________ ____ _________ _________ ____ _______ ____ ____ _______.
____ __________ _____ ________ ________ _____ ____ __________ _____ ____ __________ _______.
____ _________ _____ ____ __________ ______ _____ _________ ______ ___ _____.
_________ ____ _____ _________ ________ ______ ________ __________ ________ _______ ______ _____.
_______ __________ _________ _______ ___ ___ __________ ________ ______.
_____ ________ ________ _____ _______ ______ ________ _____.
_____ ______ ________ __________ __________ ______ ______ _______ ____ ______ _________.
________ ____ ______ ________ _________ ________ ________ _____ __________ _______.
_____ ____ ________ ______ ____ __________ ________ ________ ______ ___ ________ _____.
______ ________ __________ ___ __________ ______ ______ ___ ________ ___.
___ ________ _____ _____ ___ _______ ________ ___.
_________ _____ ____ ________ ___ _________ ___ __________.
_____ _________ _______ _________ ____ ________ ______ ________.
__________ ___ _______ ________ ___.
______ _____ ________ ___ ____ ______ ______ ____ ______.
______ ________ _________ ____ __________ ___ ______.
___ ______ ________ ______ ___ ______ _________ ________.
______ __________ _________ ________ ________ ______.
________ _________ __________ _________ ______ _______ __________ ____ ____ ______ ________.
_________ _______ ________ ______ __________ ______ _______ _________ ________ _________ _________.
_____ ______ _______ ___ ____ ______.
IGNOU ACADEMY
Your IGNOU journey, made easier.
- Solved Assignments
- Study Notes
- Guess Papers
- Question Papers
Continue Reading — It's Free
Sign in with Google to unlock more of this answer.
✓ Free access
✓ Unlock up to 60% of the answer
✓ No payment required
✓ Unlock up to 60% of the answer
✓ No payment required
Quick Google sign-in. No separate registration form.