Aug 14, 2014 at 7:53am UTC
arrayNum should be initialied like this: '0','1',2','3','4','5','6','7','8','9' since is it not a string but char.
Aceix.
Aug 14, 2014 at 10:21am UTC
The arrayNum is not needed at all. There is predicate isdigit
.
The magic - 48
assumes that the numeric value of '0' is 48. One could as well use - '0'
.
One could read one character at a time. It is safer than to assume that input has at most 49 characters.
There is predicate isspace
that could be used to spot end of word.
Aug 14, 2014 at 7:46pm UTC
some inputs:
12jksd45
output:12
12 24 or 12fjfkdfk 24
output: 3 6
12 24
output:3 6
12sdfsdf 242 sdfsdfsd43
output : 3 8 7
if you enter letter it should be ignored . (check!)
MY ONLY PROBLEM IS ! the spaces should be read. if I enter spaces between the numbers the summutation will be stop AND start another summutation again
PLEASE I NEED IT.
Last edited on Aug 14, 2014 at 7:58pm UTC
Aug 14, 2014 at 8:17pm UTC
At start, you don't have a word and the sum is 0.
Read one character at a time. If you get a digit, then you have a word and the sum increases.
If you get a whitespace and you already have a word,
then you show the sum, reset sum to 0 and you no longer have a word.
When you have run out of characters, if you still have a word, then you show the final sum.
Last edited on Aug 14, 2014 at 8:18pm UTC