Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

C Exercise 7

C Exercise 7

100 Classic C Language Examples 100 Classic C Language Examples

**Problem:** Output a special pattern; run it in a C environment and see, Very Beautiful!

**Program Analysis:** There are 256 characters in total. Different characters produce different patterns.

Chinese garbled text appears in VC6.0 (cause + solution):

The hex of 176 is B0, the hex of 219 is DB, and 0xB0DB is the internal code of the character "Bai", so the output is "Bai".

The main reason is that the code pages of the file information are different. Under the Chinese locale of the operating system we use, to display extended ASCII codes you need to display them under 437 OEM-United States, so that you can see what you want. The specific steps to modify the console's default code page are as follows:

Example

// Created by www.runoob.com on 15/11/9.

// Copyright (c) 2015 Runoob Tutorial. All rights reserved.

//

#include

<

stdio.h

int

main

(

)

{

char

a

=

176

,

b

=

219

;

printf

(

"

%c%c%c%c%c

\

n

"

,

b

,

a

,

a

,

a

,

b

)

;

printf

(

"

%c%c%c%c%c

\

n

"

,

a

,

b

,

a

,

b

,

a

)

;

printf

(

"

%c%c%c%c%c

\

n

"

,

a

,

a

,

b

,

a

,

a

)

;

printf

(

"

%c%c%c%c%c

\

n

"

,

a

,

b

,

a

,

b

,

a

)

;

printf

(

"

%c%c%c%c%c

\

n

"

,

b

,

a

,

a

,

a

,

b

)

;

return

0

;

}

The output of the above example is:

100 Classic C Language Examples 100 Classic C Language Examples