0
Why don't it count alphabet in string
9 Réponses
+ 2
This is a simplified version.
Explanation: Just iterate through the string and test if the char is a number (i.e. between 47 and 59) or an alphabet (between 97 and something(I don't remember) or between 65 and 91).
https://code.sololearn.com/cc9J9NPb66e5/?ref=app
+ 3
Your loops logic is wrong. Try to run the first loop for traversing the length of string
And than two if condition for both alphabet count and integer count.Use ASCII values provided by XXX in those if conditions.
+ 2
You are iterating in the for loop from 65 to 91. All the chars from 65 to 91 are either uppercase alphabets or are not alphabets. Your string has only lowercase letters. Refer this table for all the ASCII codes.
https://www.cs.cmu.edu/~pattis/15-1XX/common/handouts/ascii.html
Tip:
A tip for problems like this just add a printf statement and print the values in each loop. It's a very good way of debugging your work.
+ 2
1.you should have run the i loop for 4 times 0123 right now you are running it for 5 times.(0-indexing)
2. In the kth loop you are comparing k and str[k](illogical) you should have done it like k == str[i](still wrong tho :) )
3. In the if condition of the kth loop you are comparing int and char
+ 2
4. Char c = (char)j in the jth loop
in the end you are just overcomplicating things. Just think for some time what your code is actually doing. when 2 if conditions would be enough to get the work done you are using 2 loops. the logic is alright but unnecessary :)
+ 1
XXX oh yes lol,thanks
but can u check again still not working
+ 1
Abhishek Singh Negi
I get ur logic but how's my loop logic is wrong explain also u say "two if condition for both int and num"
But i want to count all alphabet in string so i have to use for loop for checking their crossponding ascii
+ 1
XXX why we have to do this why we putted int in braces
(int) line 8
+ 1
Ankit Tiwari To oh it's just me. I like to keep things clear so I know later what I've done. Even if you don't place (int) there, the code would work fine.