ソース・コードのサンプル
ILE C コンパイラーは、CCSID 290、905、および 1026 以外のあらゆる 1 バイト EBCDIC CCSID (コード化文字セット ID) で作成されたソース・コードを認識します。CCSID については、プログラムの国際化を参照してください。
C および C++ の文字セットの文字には、環境によっては使用可能でないものがあります。3 文字表記と呼ばれる 3 文字のシーケンスを 使用して、これらの文字を C または C++ ソース・プログラムに入力できま す。
注: 3 文字表記の使用について詳しくは、『ILE C/C++ 解説書』を参照してください。
C コンパイラーは 2 文字表記もサポートしています。(C++ コンパイラーは 2 文字表記をサポートしません。)
図 1. 整数の追加および文字の出力のための ILE C ソース
/* This program reads input from the terminal, displays characters, */
/* and sums and prints the digits. Enter a "+" character to */
/* indicate EOF (end-of-file). */
#define MAXLEN 60 /* The maximum input line size. */
#include <stdio.h>
#include <ctype.h>
void main(void)
{
int c;
int i = 0, j = 0;
int sum = 0;
int count, cnt;
int num[MAXLEN]; /* An array of digits. */
char letter??(MAXLEN??); /* An array of characters. Trigraphs
replace the square brackets. */
while ( ( c = getchar( ) ) != '+' )
{
if ( isalpha ( c ) ) /* A test for an alphabetic */
{ /* character. */
letter[i++] = c;
}
else if ( isdigit ( c ) ) /* A test for a decimal digit. */
{
num??(j++??) = c - '0'; /* Trigraphs replace the square
brackets. */
}
}
printf ( "Characters are " );
for ( count = 0; count < i; ++count )
{
printf ( "%c", letter[count] );
}
printf( "\nSum of Digits is " );
for ( cnt = 0; cnt < j; ++cnt )
{
sum += num[cnt];
}
printf ( "%d\n", sum );
}