Jump to content

term-printable, keymaps and c

- - - - -

  • Please log in to reply
3 replies to this topic

#1
zz5-ux

zz5-ux

    Newbie

  • Members
  • Pip
  • 2 posts
greetings, the following code demonstrates increasing a character by +1 over and over. If you replace 300 below with 900 you can see the keymap loop. Non-printable characters display in the range 31-191 and 287-299.

#include <stdio.h>

main() {

        char let = 'a';


        int x;

        for (x=0;x<300;x++) {

                printf("%d let %c\n",x,let);

                let++;

        }

}

My question is.. Are these really non-printable characters and of no use to copy/paste ability in the terminal? also.. Which numbered item is the real newline char, is that the newline shown 21 spaces before the '!' character?

Basically I am changing the characters in a string one by one using manipulation of numbers, but the end result should fall as a readable character. So a readable loop range may need to be specified when adding numbers instead of simply..
to_main[i]=to_mod[i]+32;


#2
Flying Dutchman

Flying Dutchman

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 889 posts
  • Location:::1
Printable characters start at 32, I think, that's ASCII code for space. The ones you should remember/know are '0' = 48, 'A' = 65 and 'a' = 97. You can print ASCII code yourself aswell.

for (int i = 0; i < 256; ++i)

    printf("char: %c, code %3d\n", i, i);


A conclusion is where you got tired of thinking.
#define class struct    // All is public.

#3
zz5-ux

zz5-ux

    Newbie

  • Members
  • Pip
  • 2 posts
thanks, that is a better way to display it. I ended up using.. tab[9], newline[10], readable[32->126]

#4
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,717 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript

zz5-ux said:

My question is.. Are these really non-printable characters and of no use to copy/paste ability in the terminal? also.. Which numbered item is the real newline char, is that the newline shown 21 spaces before the '!' character?
That depends on your system. On *NIX systems, 0x0a is the newline character, Windows uses 0x0d 0x0a, and Mac OS (at least the older versions) use 0x0d. You can't really assume anything about what the character set your terminal uses, so you should use the functions/macros defined in ctype.h to figure out which ones are printable. There's a function in there called isprint() that you'll find useful.
sudo rm -rf /




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users