Code Snippets
C/C++ Code Snippets
C program to print ASCII values using while loop.
By: IncludeHelp, On 17 OCT 2016
In this program we will learn how to print ASCII value along with the characters using while loop in c programming language?
Here we will print ASCII value along with the related characters from 32 to 127 using while loop, we will assign 32 to loop counter and run a loop until value will not be 127.
C program (Code Snippet) - Print ASCII of all characters using while loop
Let’s consider the following example:
/*c program to print ascii values using while loop*/
#include <stdio.h>
int main(){
unsigned char ch;
ch=32; //start with 32 (space)
while(ch<=127){
printf("%c [%03d] ",ch,ch);
ch++;
}
printf("\n");
return 0;
}
Output
[032] ! [033] " [034] # [035] $ [036] % [037] & [038] ' [039] ( [040] ) [041] * [042] + [043] , [044] - [045] . [046] / [047] 0 [048] 1 [049] 2 [050] 3 [051] 4 [052] 5 [053]
6 [054] 7 [055] 8 [056] 9 [057] : [058] ; [059] < [060] = [061] > [062] ? [063] @ [064] A [065] B [066] C [067] D [068] E [069] F [070] G [071] H [072] I [073] J [074] K [075]
L [076] M [077] N [078] O [079] P [080] Q [081] R [082] S [083] T [084] U [085] V [086] W [087] X [088] Y [089] Z [090] [ [091] \ [092] ] [093] ^ [094] _ [095] ` [096] a [097]
b [098] c [099] d [100] e [101] f [102] g [103] h [104] i [105] j [106] k [107] l [108] m [109] n [110] o [111] p [112] q [113] r [114] s [115] t [116] u [117] v [118] w [119]
x [120] y [121] z [122] { [123] | [124] } [125] ~ [126] [127]