0

Why is this program not printing any output.

#include<stdio.h>

int main()
{
    int c, i, nwhite, nother;
    nwhite = nother = 0;
    int ndigit[10];

    for(i=0; i<10; ++i)
        ndigit[i] = 0;

    while((c = getchar()) != EOF)
        if( c >= '0' && c <= '9')
            ++ndigit[c-'0'];
        else if(c == ' ' || c == '\n' || c == '\t')
            ++nwhite;
        else
            ++nother;

    for(i=0; i<10; ++i)
        printf("%d\n",ndigit[i]);
    printf("%d - %d", nwhite, nother);
}

Input: It goes on getting the input upto EOF.

7
  • So, have you tried entering some input and an EOF? Commented Feb 8, 2014 at 15:42
  • barbsbitsnbytes.com/pics/hammerd.jpg Commented Feb 8, 2014 at 15:42
  • @SakthiKumar yes. EOF is -1, i tried it but it doesnt work still.
    – ajknzhol
    Commented Feb 8, 2014 at 15:44
  • @HansPassant How should i take your comment ?
    – ajknzhol
    Commented Feb 8, 2014 at 15:45
  • Try typing control-d, or possibly control-z. Commented Feb 8, 2014 at 15:50

1 Answer 1

1

Try this:

for(i=0; i<10; ++i)
        printf("%i\n",ndigit[i]);
    printf("%i - %i", nwhite, nother);
3
  • It still gets on getting the input.
    – ajknzhol
    Commented Feb 8, 2014 at 15:42
  • @rcomp try entering Ctrl + D which is the EOF after some characters of input Commented Feb 8, 2014 at 15:44
  • 1
    @rcomp if u r in windows u have to press Ctrl + Z Commented Feb 8, 2014 at 15:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.