发明一种语言

来源:百度知道 编辑:UC知道 时间:2024/05/03 11:57:08
1) 如果单词以辅音开头,那么把起始辅音字符串(即直到第一个元音字母的所有字母)从单词开始移到尾部,并加上后缀ay。如“string”变换后为“ingstray”。
2) 如果单词以元音开头,则加后缀way。如“apple”变换后为“appleway”。

#include <stdio.h>
#include <string.h>
#define VOKAL "aeoiu"//元音
int is_vokal(char);
int find_vokal(const char*);
void convert_word(char*);
char* get_line(char*);
int main (void) {
char str[128] = {0}, word[64] = {0}, *p=str;
printf("What you want to say?\n");
get_line(str);
while(sscanf(p, "%s", word) == 1) {
convert_word(word);
p = strstr(p, " ")+1;
}
printf("\n");
return 0;}
void convert_word(char* str) {
int pos;
if (is_vokal(str[0])) printf("%sway ", str);
else {
pos=find_vokal(str);
printf("%s", str+pos);
str[pos] ='\0';
printf("%say ", str);
}
}
int find_vokal(const char* str) {
int i;
for(i=0;str[i]!='\0';i++) {
if(is_vokal(str[i])) return i;
}return -1;}
int is_vokal(char c) {