Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,436 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,327 people online right now. Registration is fast and FREE... Join Now!




alphabet counting

 
Reply to this topicStart new topic

alphabet counting

kboss
22 Jan, 2008 - 07:53 AM
Post #1

New D.I.C Head
*

Joined: 22 Jan, 2008
Posts: 2

CODE

/* This program reads input from the terminal, displays characters, */
/* and sums and prints the digits. Enter a "+" character to         */
/* indicate EOF (end-of-file).                                      */

#define MAXLEN 60               /* The maximum input line size.    */

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

void main(void)
{
    int  c;
    int  i = 0, j = 0;
    int  sum = 0;
    int  count, cnt;
    int  num[MAXLEN];            /* An array of digits.             */
    char letter??(MAXLEN??);     /* An array of characters. Trigraphs
                                   replace the square brackets.    */

    while ( ( c = getchar( ) ) != '+' )
    {
       if ( isalpha ( c ) )      /* A test for an alphabetic        */
       {                         /* character.                      */
           letter[i++] = c;
       }
       else if ( isdigit ( c ) ) /* A test for a decimal digit.     */
       {
           num??(j++??) = c - '0';  /* Trigraphs replace the square
                                       brackets.                   */
       }
    }
    printf ( "Characters are " );
    for ( count = 0; count < i; ++count )
    {
       printf ( "%c", letter[count] );
     }
    printf( "\nSum of Digits is " );
    for ( cnt = 0; cnt < j; ++cnt )
    {
        sum += num[cnt];
    }
    printf ( "%d\n", sum );
}




please help me. is this the right code to count the alphabets????
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Alphabet Counting
22 Jan, 2008 - 08:26 AM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,347



Thanked: 51 times
Dream Kudos: 25
My Contributions
Have you tried it? What was the output? Was it what you were expecting? If not, can you outline the deltas? Are you getting compiler errors? If so, can you post them?
User is online!Profile CardPM
+Quote Post

nirvanarupali
RE: Alphabet Counting
22 Jan, 2008 - 06:33 PM
Post #3

D.I.C Stomach
Group Icon

Joined: 1 Aug, 2007
Posts: 994



Thanked: 4 times
Dream Kudos: 375
My Contributions
kboss, what is your question?

Other thread, deals about counting letters.

http://www.dreamincode.net/forums/showtopic41338.htm

This post has been edited by nirvanarupali: 22 Jan, 2008 - 06:34 PM
User is offlineProfile CardPM
+Quote Post

kboss
RE: Alphabet Counting
22 Jan, 2008 - 09:22 PM
Post #4

New D.I.C Head
*

Joined: 22 Jan, 2008
Posts: 2

i tried to run but the was no output..
is it cox i m using visual c++??

i actually want to count the alphabet contains in a word( input ).
the program must autumaticly count the alphabet from a to z.
example :

kboss

a = 0
b = 1
.... till z.....

can u help me?????????
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/7/09 12:18PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month