Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 How do count letters in C?

views
     
TSHumbleBF
post May 10 2020, 06:49 PM, updated 4y ago

Casual
***
Junior Member
424 posts

Joined: Apr 2020
Real beginner in C here.

Let's say for example I want to count the letters in the sentence.


Like this sentence.

There is 15 letters above^

show 15 letters

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



int main(void)
{
//prompt user input
string t = get_string("Text: ");


//count no.of letter(s)
printf("no.of character letter(s)");

}
printf("\n");


What function could i use to count letters?
TSHumbleBF
post May 10 2020, 06:49 PM

Casual
***
Junior Member
424 posts

Joined: Apr 2020
Sorry theres 16 letters
WongGei
post May 10 2020, 06:57 PM

Regular
******
Senior Member
1,206 posts

Joined: Dec 2007
From: Kuala Lumpur
count() in algorithm

This post has been edited by WongGei: May 10 2020, 06:57 PM
malleus
post May 10 2020, 07:51 PM

Look at all my stars!!
*******
Senior Member
2,096 posts

Joined: Dec 2011
try to imagine, explaining to a 5 year old how to count the number of letters. how would you do that?
mmweric
post May 10 2020, 09:11 PM

Getting Started
**
Junior Member
156 posts

Joined: Jan 2020
QUOTE(HumbleBF @ May 10 2020, 06:49 PM)
Real beginner in C here.

Let's say for example  I want to count the letters in the sentence.
Like this sentence.

There is 15 letters above^

show 15 letters

#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <ctype.h>
int main(void)
{
    //prompt user input
    string t = get_string("Text: ");
   
   
    //count no.of letter(s)
       printf("no.of character letter(s)");
      
   }
    printf("\n");
What function could i use to count letters?
*
Do a Google search or check the reference manual faster then posting a question. First thing you need to learn in programming is how to read the reference manual or learn how to use Google .

This post has been edited by mmweric: May 10 2020, 09:14 PM
TheSolver
post May 13 2020, 09:43 PM

Regular
******
Senior Member
1,108 posts

Joined: Jun 2011
Congratulations you're learning the most popular programming language this month of May according to Tiobe Index . Basically, you're trying to implement like this in Python:
CODE
s = raw_input("Text: ")
print("no.of character letter(s): " + str(len(s)))
print("show letters: " + s);


The C Language (C99) equivalence is:
» Click to show Spoiler - click again to hide... «

The function you're interested is strlen() from <string.h> but strlen() itself is written using pointers anyway, so the routine is explicitly written for you. C is elegant isn't it? I know you're a beginner, but C is hard as demonstrated in the spoiler above. You might want to stick to Python instead. wink.gif
TSHumbleBF
post May 13 2020, 10:48 PM

Casual
***
Junior Member
424 posts

Joined: Apr 2020
QUOTE(TheSolver @ May 13 2020, 09:43 PM)
Congratulations you're learning the most popular programming language this month of May according to Tiobe Index . Basically, you're trying to implement like this in Python:
CODE
s = raw_input("Text: ")
print("no.of character letter(s): " + str(len(s)))
print("show letters: " + s);


The C Language (C99) equivalence is:
» Click to show Spoiler - click again to hide... «

The function you're interested is strlen() from <string.h> but strlen() itself is written using pointers anyway, so the routine is explicitly written for you. C is elegant isn't it? I know you're a beginner, but C is hard as demonstrated in the spoiler above. You might want to stick to Python instead. wink.gif
*
In fact... C is my first programming language, I have no basic in programming...and now I'm amazed at how simplified Python is ...

 

Change to:
| Lo-Fi Version
0.0125sec    0.44    5 queries    GZIP Disabled
Time is now: 28th March 2024 - 06:27 PM