473,503 Members | 10,245 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Program that diplays corresponding ASCII code for the numbers 0-127, 16 per line.

17 New Member
Expand|Select|Wrap|Line Numbers
  1. # include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.  char k;
  7.  for(int i=0; i<127; i++)
  8. {
  9. cout << ((char) i);
  10. k= (i+1)%16;
  11. if (k == 0)
  12. cout << "\n";
  13.  
  14. }
  15.  cout << "\n";
  16.     return 0;
  17.     }
  18.  
  19.  
  20.  
i need this to display ASCII characters for numbers 0-127, with 16 on each line. This continues to display
☺☻♥♦♣
♫☼
►◄↕‼¶§▬↨↑↓→←∟↔▲▼
!"#$%&'()*+,-./
0123456789:;<=>?
@ABCDEFGHIJKLMNO
PQRSTUVWXYZ[\]^_
`abcdefghijklmno
pqrstuvwxyz{|}~
How can i fix this problem?
Apr 7 '08 #1
5 1837
debasisdas
8,127 Recognized Expert Expert
Question moved to C / C++ Forum.
Apr 8 '08 #2
whodgson
542 Contributor
I`m not absolutely certain about this but think the first 32 ASCII characters are of non-printing type. Your code seems to work ok after 32. Why it prints out the first lot of garbage will have to be answerd by an expert.
Apr 10 '08 #3
hsn
237 New Member
you don't need to create k. create a variable called j in the for loop no rule for it just say j++;. after that an if statement that will print a new line whenever j==6 and when j==6 set it to 0.
that is a simple way or check if j is divisable by 6

good luck

hsn
Apr 10 '08 #4
Banfa
9,065 Recognized Expert Moderator Expert
I`m not absolutely certain about this but think the first 32 ASCII characters are of non-printing type. Your code seems to work ok after 32. Why it prints out the first lot of garbage will have to be answerd by an expert.
This is correct the first 32 characters in ASCII are non printable control codes. The garbage is just the displays way of dealing with these non-printable characters.

Interestingly though your thread title is ambiguous printing the ASCII code of something normally means print the numeric equivalent of a character
e.g. the ASCII code for 'A' is 65 or 0x41 in hex.

You will never be able to print the characters '\r' (code 13 or 0x0D), '\n' (code 10 oe 0x0A) and '\t' (code 9 or 0x09) without altering your display in some way.

Basically it is not possible to write this program as specified.
Apr 10 '08 #5
nothingfights
17 New Member
I eventually figured that out. Thank you.
Apr 10 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

16
2037
by: Ling Lee | last post by:
Hello. I'm trying to write a small program that lets you put in a number as an integer and then it tells you the textuel representation of the number. Like if your input is 42, it will say...
8
6696
by: sugaray | last post by:
hi, i wrote a simple base-conveter utility for practice, it seems works fine right now, hope any gurus out there can give me some suggestions to, critics of, optimisations on this program or my...
10
1871
by: Robert Rotstein | last post by:
Following is a C program, taken from http://en.wikipedia.org/wiki/Quine#Sample_quine_in_C, which has the curious property that, when executed, it produces its own source code as output. ...
1
2529
by: Willing 2 Learn | last post by:
Below is a program I did to recognize a Finite State Automata for ASCII (J+H)*. I got that one working but im having trouble getting the NFA program to work. I really desperately need help! My...
19
32754
by: many_years_after | last post by:
Hi,everyone: Have you any ideas? Say whatever you know about this. thanks.
1
1525
by: irfath | last post by:
Write an interactive program that reads three (3) lists of numbers, which are stored in three separate files, and creates one (1) sorted list. Each file should contain not more than 15 numbers....
399
12634
by: =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= | last post by:
PEP 1 specifies that PEP authors need to collect feedback from the community. As the author of PEP 3131, I'd like to encourage comments to the PEP included below, either here (comp.lang.python), or...
2
3024
by: aminnfs | last post by:
Write a program that reads in a character from the keyboard, and then displays one of the following messages: if <char> is a lower case letter, the message "The upper case character...
0
1235
by: yabighelen | last post by:
HELP!!!!! I have to write a program that does this: Create a program that encrypts and decrypts a message... Inputs: A typed message Output: When the encrypt button is clicked the input...
0
7264
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6975
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4992
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
371
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.