printf for all characters

This is a discussion on printf for all characters within the C Programming forums, part of the General Programming Boards category; How do I get this code to print vertically instead of horizontally? I want the characters to be displayed in ...

  1. #1
    Un Artiste Extraordinaire volk's Avatar
    Join Date
    Dec 2002
    Posts
    357

    Question printf for all characters

    How do I get this code to print vertically instead of horizontally? I want the characters to be displayed in this manner...

    a
    b
    c
    ...Instead of abc





    #include <stdio.h>

    main()

    {
    int c;

    for (c=0;c<256;c++)

    printf("%c",c);


    }
    Last edited by volk; 02-01-2003 at 06:06 PM.

  2. #2
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350

    Re: printf for all characters

    Originally posted by volk
    How do I get this code to print vertically instead of horizontally? I want it the the characters to be displayed in this manner...

    a
    b
    c
    ...Instead of abc
    printf("%c",c);


    }
    Code:
    unsigned ansi;
    
    for(ansi=0; ansi < 256; ansi++)
       printf("%c\n", ansi);
    What you get depends on what compiler you use.... console versus win gui, and there are several chars that are not printable.

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231

    Re: Re: printf for all characters

    >>there are several chars that are not printable.
    ... so you use the isprint() function (ctype.h) to test each value as you go through the loop, and only printf() it if it is actually printable.

    Either that or use %x to print the hex value instead of the ASCII value.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. saying hello and 1st question
    By darksys in forum C Programming
    Replies: 12
    Last Post: 10-31-2008, 03:58 PM
  2. segmentation fault upon reload
    By yabud in forum C Programming
    Replies: 8
    Last Post: 12-18-2006, 06:54 AM
  3. Simple C question: user input to repeat a loop
    By evernaut in forum C Programming
    Replies: 2
    Last Post: 11-18-2006, 09:23 AM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 02:27 PM
  5. Azbia - a simple RPG game code
    By Unregistered in forum Game Programming
    Replies: 11
    Last Post: 05-03-2002, 07:59 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21