samedi 2 mai 2020

Unable to Gain input when loop terminates

Hi All ham trying to count the number of words and characters etc.. for a project, however, in the line where I input ^D to terminate input, that line is not counted in the words characters etc..

Would appreciate you help on the same. Furthermore, I have a error: use of undeclared identifier 'str' error: use of undeclared identifier 'str' I don't know how to get rid of it.

#include <iostream>
int main()
    {
        int input;
        int words =0;
        int charecters =0;
        int spaces =0;
        int newline =0;
        int tab= 0;
        char dummy;
        while ((input=getchar())!= EOF)
        {
            if(input == ' ')
                {
                    ++spaces;
                }
            else if(input =='\n')
                {
                    ++newline;
                }
            else if(input == '\t' )
                {
                    ++tab;
                }
            else
                {
                    charecters++;
                    dummy = input;
                }
        }
        printf("The number of new lines is: %d", newline);
        printf("The number of new space is: %d", spaces);
        printf("The number of new tabs is: %d", tab);
        printf("The number of new words is: %d", words);

       return 0;

    }

Aucun commentaire:

Enregistrer un commentaire