User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 374,179 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,405 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser:
Views: 6793 | Replies: 11
Reply
Join Date: Sep 2004
Posts: 11
Reputation: Anu is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
Anu Anu is offline Offline
Newbie Poster

Prog to list ASCII codes (beginners' stuff)

  #1  
Sep 24th, 2004
Hi,

I just started a program containing every single prog we have done for school so far and added some private stuff.
Searching through my older files I found a prog which lists all Integers between 1 and 255 and their respective ASCII char, so I decided to include it into my 'collection'.

The problem is that 'twas a Win32 executable and we're working under DOS. Well actually this wouldn't be much of a problem, but the script seems no to work under DOS.

Well, first of here's the script:
  	# include <iostream.h>
   # include <conio.h>

   main()
   {
      int i, j, ip, ipp;
      float k, l;
      char zeichen;
      for (i=1;i<=254;i++)
      {
          zeichen=i;
          cout<<"\n"<<i<<" - "<<zeichen;
          j=1;
          for (j=1;j<=25;j++)
          {
               k=1.0*i/20;
               l=1.0*j;
               if (k==l)
               {
                    ip=i+1;
                    ipp=i+20;
                    if (i<=240) cout<<"\n\n(Press any key -->  "<<ip<<" to "<<ipp<<" )";
                    getch();
                    clrscr();
               };
           }
        }
        getch();
   }

As I stated, no problems under Win32, but under DOS it stops at 26 and after pressing a key again the screen gets cleared again and stays black.

So my question is..is there any way to get something like this running under DOS?

I tried a simple "cin>>intvar; charvar=intvar; cout<<charvar;" aswell, but any value above 25 simply results in nothing being put out.

Well, thanks in advance.~
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2004
Posts: 3,418
Reputation: Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light 
Rep Power: 15
Solved Threads: 137
Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Prog to list ASCII codes (beginners' stuff)

  #2  
Sep 24th, 2004
Skip 26. Or better yet, skip printing everything non-printable.
 #include <stdio.h>
 #include <ctype.h>
 
 int main(void)
 {
    int i;
    for ( i = 0; i < 256; ++i )
    {
 	  putchar(isprint(i) ? i : '.');
 	  putchar(i % 16 == 15 ? '\n' : ' ');
    }
    return 0;
 }
 
 /* my output
 . . . . . . . . . . . . . . . .
 . . . . . . . . . . . . . . . .
   ! " # $ % & ' ( ) * + , - . /
 0 1 2 3 4 5 6 7 8 9 : ; < = > ?
 @ A B C D E F G H I J K L M N O
 P Q R S T U V W X Y Z [ \ ] ^ _
 ` a b c d e f g h i j k l m n o
 p q r s t u v w x y z { | } ~ .
 . . . . . . . . . . . . . . . .
 . . . . . . . . . . . . . . . .
 . . . . . . . . . . . . . . . .
 . . . . . . . . . . . . . . . .
 . . . . . . . . . . . . . . . .
 . . . . . . . . . . . . . . . .
 . . . . . . . . . . . . . . . .
 . . . . . . . . . . . . . . . .
 */
 
Last edited by Dave Sinkula : Sep 24th, 2004 at 5:45 pm. Reason: Added code.
Reply With Quote  
Join Date: Sep 2004
Posts: 11
Reputation: Anu is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
Anu Anu is offline Offline
Newbie Poster

Re: Prog to list ASCII codes (beginners' stuff)

  #3  
Sep 24th, 2004
Originally Posted by Dave Sinkula
Skip 26. Or better yet, skip printing everything non-printable.

Wow, thanks for the fast reply.

Well, but how to skip them most easily?

The first and more or less only thing that comes into my mind is like:

if ( i != 26 && i != anotherone && i != yetanotherone &&...
Reply With Quote  
Join Date: Apr 2004
Posts: 3,418
Reputation: Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light 
Rep Power: 15
Solved Threads: 137
Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Prog to list ASCII codes (beginners' stuff)

  #4  
Sep 24th, 2004
[Oops. I see your reply beat my edit.]

I'd use isprint.

#include <stdio.h>
 #include <ctype.h>
 
 int main(void)
 {
    int i;
    for ( i = 0; i < 128; ++i )
    {
 	  putchar(isprint(i) ? i : '.');
 	  putchar(i % 32 == 31 ? '\n' : ' ');
    }
    return 0;
 }
 
 /* my output
 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
   ! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ?
 @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _
 ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~ .
 */
Reply With Quote  
Join Date: Sep 2004
Posts: 11
Reputation: Anu is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
Anu Anu is offline Offline
Newbie Poster

Re: Prog to list ASCII codes (beginners' stuff)

  #5  
Sep 24th, 2004
I see, thanks again.

But seeing this...

The output under Win32 is like:
1   - ☺ 
2   - ☻ 
3   - ♥ 
4   - ♦
5   - ♣
6   - ♠
7   -
8   -
9   -
10  -
11  - ♂
12  - ♀
13  - 
14  - ♫
15  - ☼ 
16  - ► 
17  - ◄ 
18  - ↕
19  - ‼
20  - ¶
21  - §
And so on, so...

Aint I able to display the 255 ones of those under Dos?
Reply With Quote  
Join Date: Sep 2004
Location: Overflow State
Posts: 183
Reputation: Stack Overflow is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 4
Stack Overflow's Avatar
Stack Overflow Stack Overflow is offline Offline
C Programmer

Re: Prog to list ASCII codes (beginners' stuff)

  #6  
Sep 24th, 2004
Check out http://www.asciitable.com/

The full list of ASCII characters are there. The function isprint() knows which of the characters are printable. isprint() returns a nonzero value if the input is a printable character, including the space character (0x20 – 0x7E). The other characters are either extended, or do other features which aren't print friendly.

More information on isprint()
isprint() is included in the ctype library, ctype.h:

int isprint(int c);
» This function returns nonzero if c is a space or a character for which either isalnum() or ispunct() returns nonzero.

int isalnum(int c);
» This function returns nonzero if c is any of or other locale-specific alphabetic character.
According to AsciiTable.com
Characters	ASCII
a thru z	97 thru 122
A thru Z	65 thru 90
0 thru 9	48 thru 57
int ispunct(int c);
» This function returns nonzero if c is any of the following or other implementation-defined punctuation character:
According to AsciiTable.com
Characters			ASCII
! " # $ % & ' ( ) * + , - . /	33 thru 47
: ; < = > ? @			58 thru 64
[ \ ] ^ _ '			91 thru 96
{ | } ~				123 thru 126

Hope this helps,
- Stack Overflow
Last edited by Stack Overflow : Sep 24th, 2004 at 7:15 pm. Reason: More detailed information
Following the rules will ensure you get a prompt answer to your question. If posting code, please include BB [code][/code] tags. Your question may have been asked before, try the search facility.

IRC
Channel: irc.daniweb.com
Room: #c, #shell
Reply With Quote  
Join Date: Sep 2004
Posts: 11
Reputation: Anu is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
Anu Anu is offline Offline
Newbie Poster

Re: Prog to list ASCII codes (beginners' stuff)

  #7  
Sep 24th, 2004
Thanks, might be quite of use, though probably not directly in what I'm thinking of.

See the attachments, I just want the fourth attachment (Dos, page2) to be like the second one (W32, page2).
Attached Images
File Type: jpg w32a.JPG (8.5 KB, 4 views)
File Type: jpg w32b.JPG (10.2 KB, 5 views)
File Type: jpg dosa.JPG (10.7 KB, 5 views)
File Type: jpg dosb.JPG (4.3 KB, 5 views)
Reply With Quote  
Join Date: Apr 2004
Posts: 3,418
Reputation: Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light 
Rep Power: 15
Solved Threads: 137
Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Prog to list ASCII codes (beginners' stuff)

  #8  
Sep 24th, 2004
Originally Posted by Stack Overflow
Check out http://www.asciitable.com/

The full list of ASCII characters are there. The function isprint() knows which of the characters are printable. isprint() returns a nonzero value if the input is a printable character, including the space character (0x20 – 0x7E). The other characters are either extended, or do other features which aren't print friendly.

More information on isprint()
isprint() is included in the ctype library, ctype.h:

int isprint(int c);
» This function returns nonzero if c is a space or a character for which either isalnum() or ispunct() returns nonzero.

int isalnum(int c);
» This function returns nonzero if c is any of or other locale-specific alphabetic character.
According to AsciiTable.com
 Characters	ASCII
 a thru z	97 thru 122
 A thru Z	65 thru 90
 0 thru 9	48 thru 57
int ispunct(int c);
» This function returns nonzero if c is any of the following or other implementation-defined punctuation character:
According to AsciiTable.com
 Characters			ASCII
 ! " # $ % & ' ( ) * + , - . /	33 thru 47
 : ; < = > ? @			58 thru 64
 [ \ ] ^ _ '			91 thru 96
 { | } ~				123 thru 126

Hope this helps,
- Stack Overflow
The greater utility of functions like ispunct and isalnum are that they also work with other character sets, some of which, for example, do not necessarily have a contiguous alphabet or such. They are designed to work regardless of the particular implementation.
Reply With Quote  
Join Date: Apr 2004
Posts: 3,418
Reputation: Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light 
Rep Power: 15
Solved Threads: 137
Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Prog to list ASCII codes (beginners' stuff)

  #9  
Sep 24th, 2004
Originally Posted by Anu
See the attachments, I just want the fourth attachment (Dos, page2) to be like the second one (W32, page2).
DOS has a particular issue with the value 26. Apparently it is an end-of-file marker. So on a DOS system, it will not work the way you'd like. Thus my recommendation to skip it.
Reply With Quote  
Join Date: Sep 2004
Posts: 11
Reputation: Anu is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
Anu Anu is offline Offline
Newbie Poster

Re: Prog to list ASCII codes (beginners' stuff)

  #10  
Sep 25th, 2004
That was all I actually wanted to know. Thanks once again. ^^
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb C Marketplace
Thread Tools Display Modes

Other Threads in the C Forum

All times are GMT -4. The time now is 4:36 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC