My English is very bad but I hope you can understand me!
Furthermore: I have never programmed before and this year I started with a study where programming is essential.
Hello readers,
For a homework assignment I have to make a program that counts digits and other charachters from the keyboard (what the user types in) and I have to make use of the function getchar until a EOF occurs.
Furthermore I have to use the variables "Digits" and "Others" to count the inputted digits and other characters.
Also I am not allowed to use strings. I can only use getchar and putchar and loops.
To make sure if it is a digit or a other character I have to use the function isdigit in the ctype header.
I dont know how to go further....
I tried very many things but nothing worked I only got weird charachters like smileys and other stuff...
I hope someone can help me!!
#include <stdio.h>
#include <ctype.h>
int main()
{
int digit = 0;
int other = 0;
char c;
while((c=getchar()) !=EOF)
{
if(isdigit(c))
{
putchar(c);
digit ++;
}
else
other++;
}
}
this stores the number of digits in the variable digit and the number of other chars in the variable other, becourse everytime isdigit(c) returns true the number of digits is incremented by one.
i think you should be able to gues the rest.