本プログラムは、1つの音節の綴りを表示するプログラムである。
文字1字につき1つの音素を表すものとし、母音字1つで1つの母音が、子音字1つで1つの子音が表されるものとする。
音節は、「母音1つ」、「1つまたは複数の子音 - 1つの母音 - 1つまたは複数の子音」、「1つまたは複数の子音 - 1つの母音」、「1つの母音 - 1つまたは複数の子音」のいずれかの形式で成り立つものとする。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>
typedef union syllable{
struct
{
char H_con[4]; //頭子音
char vowel; //母音
char T_con[3]; //尾子音
} part;
char all[9];
} syllable; //音節を格納する構造体
struct
{
char H_con[4]; //頭子音
char vowel; //母音
char T_con[3]; //尾子音
} part;
char all[9];
} syllable; //音節を格納する構造体
syllable a;
void H_con_select(void);
char vowel_select(void);
void T_con_select(void);
char vowel_select(void);
void T_con_select(void);
int main(void)
{
int i;
{
int i;
srand*1;
for(i=0;i<9;i++) a.all[i] = '\0'; //変数aを空に
if(rand() % 100 <75) H_con_select(); //75%の確率で頭子音を
a.part.vowel = vowel_select(); /*母音を選ぶ*/
if(rand() % 100 <50) T_con_select(); //50%の確率で尾子音を
a.part.vowel = vowel_select(); /*母音を選ぶ*/
if(rand() % 100 <50) T_con_select(); //50%の確率で尾子音を
printf("%s",a.part.H_con);
putchar(a.part.vowel);
printf("%s",a.part.T_con);
}
putchar(a.part.vowel);
printf("%s",a.part.T_con);
}
void H_con_select(void)
{
switch(rand() % 40) //40種類の頭子音の中から1つを選ぶ
{
case 0:
strcpy(a.part.H_con,"h");
break;
case 1:
strcpy(a.part.H_con,"c");
break;
case 2:
strcpy(a.part.H_con,"g");
break;
case 3:
strcpy(a.part.H_con,"j");
break;
case 4:
strcpy(a.part.H_con,"t");
break;
case 5:
strcpy(a.part.H_con,"d");
break;
case 6:
strcpy(a.part.H_con,"n");
break;
case 7:
strcpy(a.part.H_con,"s");
break;
case 8:
strcpy(a.part.H_con,"z");
break;
case 9:
strcpy(a.part.H_con,"l");
break;
case 10:
strcpy(a.part.H_con,"r");
break;
case 11:
strcpy(a.part.H_con,"f");
break;
case 12:
strcpy(a.part.H_con,"v");
break;
case 13:
strcpy(a.part.H_con,"p");
break;
case 14:
strcpy(a.part.H_con,"b");
break;
case 15:
strcpy(a.part.H_con,"m");
break;
case 16:
strcpy(a.part.H_con,"sc");
break;
case 17:
strcpy(a.part.H_con,"st");
break;
case 18:
strcpy(a.part.H_con,"sn");
break;
case 19:
strcpy(a.part.H_con,"sl");
break;
case 20:
strcpy(a.part.H_con,"sp");
break;
case 21:
strcpy(a.part.H_con,"sm");
break;
case 22:
strcpy(a.part.H_con,"scr");
break;
case 23:
strcpy(a.part.H_con,"cr");
break;
case 24:
strcpy(a.part.H_con,"gr");
break;
case 25:
strcpy(a.part.H_con,"str");
break;
case 26:
strcpy(a.part.H_con,"tr");
break;
case 27:
strcpy(a.part.H_con,"dr");
break;
case 28:
strcpy(a.part.H_con,"spr");
break;
case 29:
strcpy(a.part.H_con,"pr");
break;
case 30:
strcpy(a.part.H_con,"br");
break;
case 31:
strcpy(a.part.H_con,"fr");
break;
case 32:
strcpy(a.part.H_con,"scl");
break;
case 33:
strcpy(a.part.H_con,"cl");
break;
case 34:
strcpy(a.part.H_con,"gl");
break;
case 35:
strcpy(a.part.H_con,"sl");
break;
case 36:
strcpy(a.part.H_con,"spl");
break;
case 37:
strcpy(a.part.H_con,"pl");
break;
case 38:
strcpy(a.part.H_con,"bl");
break;
case 39:
strcpy(a.part.H_con,"fl");
break;
}
}
{
switch(rand() % 40) //40種類の頭子音の中から1つを選ぶ
{
case 0:
strcpy(a.part.H_con,"h");
break;
case 1:
strcpy(a.part.H_con,"c");
break;
case 2:
strcpy(a.part.H_con,"g");
break;
case 3:
strcpy(a.part.H_con,"j");
break;
case 4:
strcpy(a.part.H_con,"t");
break;
case 5:
strcpy(a.part.H_con,"d");
break;
case 6:
strcpy(a.part.H_con,"n");
break;
case 7:
strcpy(a.part.H_con,"s");
break;
case 8:
strcpy(a.part.H_con,"z");
break;
case 9:
strcpy(a.part.H_con,"l");
break;
case 10:
strcpy(a.part.H_con,"r");
break;
case 11:
strcpy(a.part.H_con,"f");
break;
case 12:
strcpy(a.part.H_con,"v");
break;
case 13:
strcpy(a.part.H_con,"p");
break;
case 14:
strcpy(a.part.H_con,"b");
break;
case 15:
strcpy(a.part.H_con,"m");
break;
case 16:
strcpy(a.part.H_con,"sc");
break;
case 17:
strcpy(a.part.H_con,"st");
break;
case 18:
strcpy(a.part.H_con,"sn");
break;
case 19:
strcpy(a.part.H_con,"sl");
break;
case 20:
strcpy(a.part.H_con,"sp");
break;
case 21:
strcpy(a.part.H_con,"sm");
break;
case 22:
strcpy(a.part.H_con,"scr");
break;
case 23:
strcpy(a.part.H_con,"cr");
break;
case 24:
strcpy(a.part.H_con,"gr");
break;
case 25:
strcpy(a.part.H_con,"str");
break;
case 26:
strcpy(a.part.H_con,"tr");
break;
case 27:
strcpy(a.part.H_con,"dr");
break;
case 28:
strcpy(a.part.H_con,"spr");
break;
case 29:
strcpy(a.part.H_con,"pr");
break;
case 30:
strcpy(a.part.H_con,"br");
break;
case 31:
strcpy(a.part.H_con,"fr");
break;
case 32:
strcpy(a.part.H_con,"scl");
break;
case 33:
strcpy(a.part.H_con,"cl");
break;
case 34:
strcpy(a.part.H_con,"gl");
break;
case 35:
strcpy(a.part.H_con,"sl");
break;
case 36:
strcpy(a.part.H_con,"spl");
break;
case 37:
strcpy(a.part.H_con,"pl");
break;
case 38:
strcpy(a.part.H_con,"bl");
break;
case 39:
strcpy(a.part.H_con,"fl");
break;
}
}
「母音字と子音字の配置法を考慮し、適当な文字列を表示するプログラム 後」に続く。
*1:unsigned) time(NULL