You are on page 1of 10

II

5.3

5.3:

45

( 5.4
5.5

5.4:

5.5:

46

47

6.1

6.1:

GUI CUI
GUI

6.1

6.1

50 1
DX
1
1 25 2 26 50

6.1: message-cui-01.cpp
1
2

# include <stdio .h>


# include <string .h>

3
4
5

//
char g_message [256] = " HelloWorld ";

6
7
8
9
10
11
12

// m e s s a g e start len
void writeSubstring (char* message , int start , int len)
{
int i;
//
int maxLen = strlen ( message );

13

// s t a r t
if( start >= maxLen ) {
return ;
}

14
15
16
17
18

// l e n
for( i = 0; i < len && message [ start + i ] != \0 ; i++ ) {
printf ("%c", message [ start + i ] );
}
printf ("\n");

19
20
21
22
23
24

25
26
27
28
29
30
31
32
33
34
35
36
37

int main ()
{
// g _ m e s s a g e
writeSubstring (g_message , 0, strlen ( g_message ) );
// g_message 2 ( g_message [1] ) 5
writeSubstring (g_message , 1, 5);
// g_message 6 ( g_message [5] ) 10
//10
writeSubstring (g_message , 5, 10);
// g_message 20
writeSubstring (g_message , 20, 10);
}

writeSubstring message start len


main

48

HelloWorld
elloW
World

writeSubstring
1 g message HelloWorld
1 0

2 2 5 3 5
10 HelloWorld 6 10
6
writeSubstring 20 10 HelloWorld 20

6.2

writeSubstring

char1 1byte)
char 2
SHIFT JIS 1 3
(char3
Windows Linux
Windows
SHIFT JIS

6.2: message-cui-02.cpp
1
2

# include <stdio.h>
# include <string .h>

3
4
5
6

// S H I F T _ J I S W i n d o w s
//

// S H I F T _ J I S 2

7
8
9

//
char g_message [256] = " ";

10
11
12
13
14
15
16

// m e s s a g e start len
void writeSubstring (char* message , int start , int len)
{
int i;
//
int maxLen = strlen ( message );

17
1

SHIFT JIS Windows .

49

6.3
// 2
start *= 2;
len *= 2;

18
19
20
21

// s t a r t
if( start >= maxLen ) {
return ;
}

22
23
24
25
26

// l e n
for( i = 0; i < len && message [ start + i ] != \0 ; i += 2 ) {
printf ("%c", message [ start + i ] );
printf ("%c", message [ start + i + 1 ]);
}
printf ("\n");

27
28
29
30
31
32
33

34
35
36
37
38
39
40
41
42
43
44
45
46

int main ()
{
// g _ m e s s a g e
writeSubstring (g_message , 0, strlen ( g_message ) );
// g_message 2 5
writeSubstring (g_message , 1, 5);
// g_message 6 10
//10
writeSubstring (g_message , 5, 10);
// g_message 20
writeSubstring (g_message , 20, 10);
}

6.3

1
2
SHIFT JIS 2 1
2

SHIFT JIS 2 0x810x9f 0xe00xfc


char

50

//code
// 1: 0:
int isJapaneseCharacter(unsigned char code)
{
if( (code >= 0x81 && code <= 0x9F) ||
(code >= 0xE0 && code <= 0xFC) ) {
return 1;
}
return 0;
}

1
2
3
4
5
6
7
8
9
10

6.3: message-cui-03.cpp
1
2

# include <stdio.h>
# include <string .h>

3
4

// S H I F T _ J I S 0 x 8 1 0 x 9 F 0 x E 0 0 x F C

5
6
7
8
9
10
11
12
13
14
15

// code
// 1: 0:
int isJapaneseCharacter ( unsigned char code)
{
if( (code >= 0x81 && code <= 0x9F) ||
(code >= 0xE0 && code <= 0xFC) ) {
return 1;
}
return 0;
}

16
17
18
19
20
21

int main ()
{
char check_first [3] = " ";
char check_second [3] = " ";
char check_third [3] = "h";

22

printf (" , %d\n", isJapaneseCharacter ( check_first [0] ) );


printf (" %d\n", isJapaneseCharacter ( check_second [0] ) );
printf (" h % d\n", isJapaneseCharacter ( check_third [0] ) );

23
24
25
26

return 0;

27
28

, 1
1
h 0

writeSubstring

51

6.4

6.4

writeSubstring

Hello World

6.4: message-cui-04.cpp
1
2

# include <stdio .h>


# include <string .h>

3
4
5
6
7

// S H I F T _ J I S W i n d o w s
//

// S H I F T _ J I S 2
// 0 x 8 1 0 x 9 F 0 x E 0 0 x F C

8
9
10

//
char g_message [256] = " H e l l o W o r l d ";

11
12
13
14
15
16
17
18
19
20
21
22

// code
// 1: 0:
int isJapaneseCharacter ( unsigned char code)
{
if( (code >= 0x81 && code <= 0x9F) ||
(code >= 0xE0 && code <= 0xFC) ) {
return 1;
}
return 0;
}

23
24
25
26
27
28
29
30

// m e s s a g e start len
void writeSubstring (char* message , int start , int len)
{
int i;
//
int maxLen = strlen ( message );

31
32
33
34
35
36
37
38
39
40
41
42
43
44

// s t a r t
// s t a r t 1
for( i = 0; i < start && message [i] != \0; ) {
if( isJapaneseCharacter ( message [i] ) ) {
// 2
i += 2;
// s t a r t 1
start ++;
}else {
// 1
i++;
}
}

45
46
47
48
49

// s t a r t
if( start >= maxLen ) {
return ;
}

50
51

// l e n

52

You might also like