Total members 11894 |It is currently Thu Nov 21, 2024 5:08 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Printing the ASCII codes to the screen.
cpp code
/*
* This program prints out a table of the ascii character values.
*/
#include <stdio.h>
#include <ctype.h>

int main()
{
int code; /* Ascii value. */

for(code = 0; code < 128; ++code) {
/* Print the code and the character itself. */
printf("%3d ", code);
if(isspace(code))
printf(" ");
else if(isprint(code))
printf("%c", code);
else
printf(" ");

/* If any of the interesting categories match, print it. */
if(code == '\n')
printf(" (newline, \\n)\n");
else if(code == ' ')
printf(" (space)\n");
else if(code == '\t')
printf(" (tab, \\t)\n");
else if(isspace(code))
printf(" (blank character)\n");
else if(iscntrl(code))
printf(" (control character)\n");
else if(isupper(code))
printf(" (capitol of %c)\n", tolower(code));
else if(islower(code))
printf(" (lower case of %c)\n", toupper(code));
else if(isdigit(code))
printf(" (digit)\n", toupper(code));
else
putchar('\n');
}
}


In the first printf, the construct %3d is the same as %d, except that printf is instructed to use at least three spaces to represent the number, padding with spaces at the left if necessary. (Use %-3d if you want the padding on the right.) This just keeps the output nicely aligned.

Notice how the integer value code is printed both with %d to get the integer value, and with %c to get the character itself. This works equally well if the variable is declared as char: it can be printed with either %d or %c.



_________________
Please recommend my post if you found it helpful


Author:
Beginner
User avatar Posts: 95
Have thanks: 2 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Print the ASCII Set
 ascii codes using of it in c     -  
 few examples of c using ascii     -  
 Unicode, ASCII, UTF-16, and UTF-8 characters in java     -  
 How to save in a file the ASCII Characters? Like "☺"     -  
 Help for Print using php     -  
 Print all MySQL status value     -  
 print element in 2d matrix     -  
 How to print a webcam picture in Jsp     -  
 Print all files in a directory     -  
 Get union of two arrays set and print it     -  



Topic Tags

C++ Basics, C++ Variables






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com