A = 1 so on then small letters a = 27 using ascii please help thank you so much
c language for loop and ascii input1 output= A then small letters a=27 so on
Collapse
X
-
It's only doing the capitalsCode:#include "stdio.h" int main() { int i=1; while (i<=26) { printf("%c=%i\n", (char)(i+64), i); i=i+1; } return 0; }
But, I wonder, what are you going to do with this piece of code that you probably do not understand?
Or can you show everybody here how to expand this piece of code to do also the lower-case letters?
And, finally, yes, I am no a C-programmer ... ;) -
The C Standard does not mandate ASCII encoding for characters. Code that assumes ASCII encoding is not portable. Perhaps the assignment requires you to make this assumption.
On the other hand, you could iterate an int variable from CHAR_MIN to CHAR_MAX (from limits.h), and then use character classification functions (from ctype.h) to identify, for example, alphabetic, uppercase, and lowercase characters, and finally print the decoded and encoded values for characters that make it through the classification filter.
Why did I say int variable rather than char variable? Because (1) the int range is a superset of the char range (that is, a char can be assigned to an int without any loss of sign or precision); and (2) the character classification functions take an int argument.Comment
-
My mistake, I thought he wanted to print the encoded value for each letter.
Your code assumes that if you sort the uppercase letters in alphabetic order then the corresponding encoded values increase monotonically (but the values need not be contiguous); it makes the same assumption regarding the lowercase letters; and it assumes all uppercase letters have smaller encoded values than any lowercase letter.
These assumptions are true for ASCII encoding but I don’t know that the C Standard requires that they be true for any and all character encodings.Comment
-
LOL the order of characters, in 'any' encoding i know of, is the same as in ASCII.
Probably just to make sure every system can order alphabetically. ..
(and lazyness of everyone who invented another character encoding...)
But, as far as, he C Standard requires things, you are right!
(But i never read a document about that subject, as fara as i can remember!)Comment
-
EBCDIC has smaller encoded values for lowercase than for uppercase. This violates the third assumption.
A portable approach is to iterate through the literal string constant "ABC...XYZabc.. .xyz". The array index is the rvalue and the corresponding element in the array is the lvalue. However, whether this solves the OP's problem depends on the precise wording of the assignment.Comment
Comment