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 8252455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:34:14+00:00 2026-06-08T00:34:14+00:00

First, my objective with this code: take in a sentence into a C string.

  • 0

First, my objective with this code: take in a sentence into a C string. Iterate through the sentence and see how many instances of a particular letter occur.

This code is working somewhat but not giving the right number? Not sure why:

#include <stdio.h>
#include <string.h>

int tracker=0;
int letterCount (char *sentence)
{
    int s=strlen(sentence);
    int i=0;


    for (i=0; i<s; i++){
        if (sentence[i]=='h') {
            tracker++;
        }
    }
    return tracker;
}

int main(int argc, const char * argv[])
{

    char *string="Hi there, what's going on? How's it going?";


    letterCount(string);

    printf("this sentensce has %i H's", tracker);


    return 0;
}

The output I’m getting:

this sentensce has 2 H's

Not quite right. Any ideas?

  • 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-08T00:34:15+00:00Added an answer on June 8, 2026 at 12:34 am

    This is the correct code if you mean case insensitive H:

    #include <stdio.h>
    #include <string.h>
    
    int tracker=0;
    int letterCount (char *sentence)
    {
        int s=strlen(sentence);
        int i=0;
    
    
        for (i=0; i<s; i++){
            if (sentence[i]=='h' || sentence[i]=='H') {  //'h' is not the same as 'H'
                tracker++;
            }
        }
        return tracker;
    }
    
    int main(int argc, const char * argv[])
    {
    
        char *string="Hi there, what's going on? How's it going?";
    
    
        letterCount(string);
    
        printf("this sentensce has %i H's", tracker);
    
    
        return 0;
    }
    

    You have just mispelled small and the capital letter in your code.
    Remember, the C language is case sensitive!

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

Sidebar

Related Questions

First of all, I found this: Objective C HTML escape/unescape , but it doesn't
First, new to Cocoa and Objective-C, so my apologies if this is unclear and
I am new to Objective-C programming. In many tutorials I have been seeing code
I'm trying to draw the following image: Using this objective-c code: CGContextSetFillColorWithColor(ctx, [[UIColor redColor]
I'm a first time Objective C programmer. I've been reading other people's code and
So I'm toying with this code here, and the main objective is to update
Why is this CLLocationManager inside my singleton not working? I took this code http://jinru.wordpress.com/2010/08/15/singletons-in-objective-c-an-example-of-cllocationmanager/
Possible Duplicate: Objective-C NSMutableArray mutated while being enumerated? I use this code to remove
Can anyone see if there is something wrong in my matlab code? My objective
I am working on my first Objective-C app for iOS and am having an

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.