C 土耳其语元音字母识别

C 土耳其语元音字母识别,c,C,我想生成代码; 当您输入句子时,系统将仅显示这些句子的辅音字母 我生成了代码,但代码不能识别特殊的土耳其元音字母 像İ,Ü,Ö一样是一个常量字母。只能识别英语拉丁元音字母 我怎样才能解决这个问题 #include <stdio.h> #include <string.h> #include <time.h> #include <wchar.h> int vowel (char); int main () { setlocale(LC_

我想生成代码; 当您输入句子时,系统将仅显示这些句子的辅音字母

我生成了代码,但代码不能识别特殊的土耳其元音字母 像İ,Ü,Ö一样是一个常量字母。只能识别英语拉丁元音字母

我怎样才能解决这个问题

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

int vowel (char);

int main () 
{
    setlocale(LC_ALL, "Turkish");
    char s[100], t[100];
    int c, d = 0;
    printf ("Enter sentence vowels will ve removed:\n");
    gets (s);
    for (c = 0; s[c] != '\0'; c++)
    {
        if (vowel (s[c]) == 0)
        {           
            t[d] = s[c];
            d++;
        }
    }
    t[d] = '\0';
    strcpy (s, t);      
    printf ("Letters without vowels: %s\n", s);
    return 0;
}

int vowel (char ch) 
{
    if (ch == 'a' || ch == 'A'
     || ch == 'e' || ch == 'E'
     || ch == 'ı' || ch == 'I'
     || ch == 'i' || ch == 'İ'
     || ch == 'o' || ch == 'O'
     || ch == 'ö;' || ch == 'Ö'
     || ch == 'u' || ch == 'U'
     || ch == 'ü' || ch == 'Ü')
      return 1;
    else
      return 0;
}
#包括
#包括
#包括
#包括
int元音(char);
int main()
{
setlocale(土耳其语);
字符s[100],t[100];
int c,d=0;
printf(“输入句子元音将被删除:\n”);
获取(s);
对于(c=0;s[c]!='\0';c++)
{
if(元音(s[c])==0)
{           
t[d]=s[c];
d++;
}
}
t[d]='\0';
strcpy(s,t);
printf(“没有元音的字母:%s\n”,s);
返回0;
}
int元音(char-ch)
{
如果(ch='a'| ch='a'
||ch==“e”| ch==“e”
||ch==‘我’
||ch==“i”| ch==“İ”
||ch==“o”| ch==“o”
||ch='ö;'| | ch='Ö'
||ch=='u'| | ch=='u'
||ch==‘ü’| ch==‘Ü’)
返回1;
其他的
返回0;
}

我将其重写为使用
wchar\u t
而不是char

Ascii字符以单字节(char)表示。您可能需要将代码转换为使用
wchar\t

#include <locale.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <wchar.h>

int vowel (wchar_t); // <---- accepts wchar_t instead of char

int main ()
{
    setlocale(LC_ALL, "Turkish");
    /* To get it to work on https://www.onlinegdb.com/
     * use setlocale(LC_ALL,"en_US.UTF-8");
     * 
     */
    wchar_t s[100], t[100]; // <---- wchar_t instead of char
    int c, d = 0;
    printf ("Enter sentence vowels will ve removed:\n");

    // TODO : also check the return code. On error, it returns NULL.
    fgetws (s, 100, stdin); // <----- accepting wchar_t string

    for (c = 0; s[c] != '\0'; c++)
    {
        if (vowel (s[c]) == 0)
        {
            t[d] = s[c];
            d++;
        }
    }
    t[d] = '\0';
    // using memcpy instead of strcpy.
    // also see - http://www.cplusplus.com/reference/cwchar/wcscpy/
    memcpy (s, t, sizeof(t));
    printf ("Letters without vowels: ");
    for (c = 0; c < d; c++)
        putwchar(s[c]); // <---- print wchar_t character on terminal
    putwchar('\n');
    return 0;
}

int vowel (wchar_t ch)
{
    // I've prefixed an L - more than one byte.
    if (ch == L'a' || ch == L'A'
     || ch == L'e' || ch == L'E'
     || ch == L'ı' || ch == L'I'
     || ch == L'i' || ch == L'İ'
     || ch == L'o' || ch == L'O'
     || ch == L'ö' || ch == L'Ö'
     || ch == L'u' || ch == L'U'
     || ch == L'ü' || ch == L'Ü')
      return 1;
    else
      return 0;
}

亲爱的@algrebe非常感谢您的快速回复。我在上运行了代码,但在onlinegdb上土耳其语元音显示为问号

Enter sentence vowels will ve removed:                                                                                                        
avbcdxyÖÜ                                                                                                                                     
setters without vowels: vbcdxys�� 

缩进对编译器来说可能并不重要,但对我们这些试图阅读和理解代码的人来说是重要的。请你的问题得到一致的缩进。在另一个(但不相关)注释中,如果你有一个函数,
if(某些条件)返回1;否则返回0
您可以用单个语句替换它
返回一些\u条件。最后一个问题:这些字符是8位字符集的一部分吗(通常是从
128
255
的值)?如果是,请让编辑器将其保存为源文件中的8位字符(使用十六进制编辑器查看,并检查编辑器首选项是否设置为Unicode或UTF-8或类似格式)?
aeiou
和大写等效值介于0-255之间(字符类型,8位)。但是,更复杂的字符(如土耳其符号)将由unicode表示。它们可能不适合单个字节。您可能需要在元音函数中接受
wchar\u t
,而不是
char
。程序是否编译?至少从这里显示的方式来看,
'o'| |'o'
后面的行似乎在
'
中有两个字符,第二个是
可能是onlinegdb不支持土耳其语言环境。我把它改成了使用en_US.UTF-8,现在可以在那里使用了。
Enter sentence vowels will ve removed:                                                                                                        
avbcdxyÖÜ                                                                                                                                     
setters without vowels: vbcdxys��