by Anonymous on August 7th, 2009

Anonymous

Question

Help answer this question below.

Can any body help to write a program in c to count no.of char ,spaces,digitsand other

  • Like
  • Report

Answers. 2 helpful answers below.

  • by POP Fan on August 15th, 2009

    POP Fan

    In what? In a string? Its very easy:
    ...
    ...
    #include <string.h>
    ...
    ...

    int main(int argc, int *argv[])
    {
    int a;
    char s[80];
    ...
    ...
    a=strlen(s);
    ...
    ...

    The strlen function:
    int strlen(const char *a)

    defined in string.h counts the number of characters within the string pointed to by a and returns the value. The null character at the end is not counted.

    • Like
    • Report

    3 comments | Post one | Permalink

  • by randomguy on August 20th, 2009

    randomguy

    If you are working in ASCII characters then you can do something like this:

    int main(char *str)
    {
    int values = 0;
    int check[256];
    check[' '] = 1;
    check['0'] = 1;
    ...

    while(str)
    values += check[*(str++)];

    return values;
    }

Want to attach an image to your answer? Click here.

Did this answer your question? If not, then ask a new question or create a poll.

More Questions. Additional questions in this category.

You're reading Can any body help to write a program in c to count no.of char ,spaces,digitsand other

Follow us on Facebook!

Related Ads