Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8729413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:49:42+00:00 2026-06-13T08:49:42+00:00

I wanted to write a program which counts the occurrences of each letter in

  • 0

I wanted to write a program which counts the occurrences of each letter in a string, then prints one of each letter followed by the count for that letter.

For example:

aabbcccd –
Has 2 a, 2 b, 3 c, and 1 d

So I’d like to convert and print this as:

a2b2c3d1

I wrote code (see below) to perform this count/conversion but for some reason I’m not seeing any output.

#include<stdio.h>
main()
{
    char array[]="aabbcccd";
    char type,*count,*cp=array;
    while(cp!='\0'){
      type=*cp;
      cp++;
      count=cp;
      int c;
      for(c=1;*cp==type;c++,cp++);
      *count='0'+c;
    }
    count++;   
    *count='\0';
    printf("%s",array);
}

Can anyone help me understand why I’m not seeing any output from printf()?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:49:43+00:00Added an answer on June 13, 2026 at 8:49 am
    char array[]="aabbcccd";
    char type,*count,*cp=array;
    while(cp!='\0'){ 
    

    *cp is a pointer it’s pointing to the address of the start of the array, it will never be == to a char '\0' so it can’t leave the loop.

    You need to deference the pointer to get what it’s pointing at:

    while(*cp != '\0') {
    ...
    

    Also, you have a ; after your for loop, skipping the contents of it:

    for(c=1;*cp==type;c++,cp++); <-- this ; makes it not execute the code beneath it
    

    After fixing both of those problems the code produces an output:

    mike@linux-4puc:~> ./a.out 
    a1b1c2cd
    

    Not the one you wanted yet, but that fixes your problems with “printf not functional”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a huge text file and I wanted to write a program which
I wanted to write a short programm, which replaces the Counting of a String.
I wanted to write a short programm, which replaces the Counting of a String.
I wanted to write a program that test if two files are duplicates (have
Say I wanted to write a program that would export calendar data so that
I wanted to write a timer in java.which will do the following: when program
I've started learning Lisp recently and wanted to write a program which uses gtk
this is a very basic program I wanted to write a VB script which
I wanted to write a program which writes to multiple files simultaneously; thought it
I wanted to write a function that'll be cross platform (win32 & linux), and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.