0

My coding is like this - it is for the spiral. I tried to do it but it doesn't work. If any one has any idea how to do it please advise.

#include "stdio.h"
#include "conio.h"

void main ()
{
    int p,q;

    for(p=0; p<100; p++)
    {
        printf("alt+219");\\where alt+219 is an ASCII character in C\\
    }
    for(q=0; q<100; q++)
    {
        printf("alt+220");\\where alt+220 is an ASCII character in C\\
    }
}
Paul R
  • 208,748
  • 37
  • 389
  • 560

2 Answers2

0

One interesting way of doing these "text graphics" kind of problems I encountered (when such problems were in vogue) is to have a 2D loop, and then use a function to decide what to print using a function, rather than to have multiple loops.

For example, for a criss-cross pattern, we could define char_to_print(x, y) = 'x' if ((x+y)%2 == 0) else ' ' (this is not C/C++).

Just some food for thought.

lijie
  • 4,811
  • 22
  • 26
  • lijie i didn't understand your logic can little more describe it it would be more helpful for me thanksss.. – user517026 Nov 23 '10 at 16:43
  • @user517026: lijie means something like what most answers to http://stackoverflow.com/q/3365487/371250 do, i.e. Have a couple of loops iterating over x and y, covering the whole output surface, and for each point there call a function returning what to draw at those coordinates. – ninjalj Nov 23 '10 at 19:44
  • @user517026: i don't really understand what the "spiral" or "checker board" look like, so maybe an example of the output help? – lijie Nov 24 '10 at 02:09
0

If you want to put them into a literal string, hex for 219 is DB and for 220 is DC so you can output '\xDB' or '\xDC'.

You could also use %c in printf and put the numbers in thus printf("%c", 219)

If you are going to go into UTF-16 and use wprintf you can use %lc with the code you want. %c will automatically perform btowc on your value.

BTW, main should return int, not void.

CashCow
  • 30,981
  • 5
  • 61
  • 92