I'm making a simple counting program that will count the amount of digits, white spaces and other things.
It's a textbook example but I just can't get the hang of it.
I've written it like it should be (I think),
but when I want to test it, it just functions like a notepad.
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int c, i, nwhite, nother;
int ndigit[10];
nwhite = nother = 0;
for (i = 0; i < 10; i++)
ndigit[i] = 0;
while (( c = getchar()) != EOF){
if
(c >= '0' && c <= '9')
++ndigit[c-'0'];
elseif
(c == ' ' || c == '\t' || c == '\n')
++nwhite;
else
++nother;
}
printf("digits =");
for (i = 0; i < 10; i++)
printf(" %d", ndigit[i]);
printf(", white space = %d, other = %d\n", nwhite, nother);
}
That's the output I was looking for.
I have a C++ manual that my college gave us where exactly this code is used and the output is also given.
When I tried it myself, I just didn't get an output.