Question

Using Pointers,

  1. Write the character-counting function
  2. Write the string-concatenation program

 

30 Nov 2017
Answer :
Word Count : 377

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_characters function 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
Skip in 10
Top
📞
Call Support Instant phone assistance IGNOU MCS 11 2010 - Using Pointers, Write the character-counting function Write | IGNOU Academy
→
🟢
WhatsApp Chat Fast live messaging
→
Email Us Business enquiries & support
→