Bạn đang ở đây
C chương trình để xóa hoặc xóa nguyên âm khỏi một chuỗi. Nếu đầu vào là "lập trình C", thì đầu ra là "C prgrmmng." Trong chương trình, chúng tôi tạo một chuỗi chuỗi đầu vào mới và quy trình theo ký tự. Nếu một nguyên âm có mặt, chúng tôi loại trừ nó nếu không chúng tôi sao chép nó. Sau khi đầu vào kết thúc, chúng tôi sao chép chuỗi mới vào nó. Cuối cùng, chúng tôi có được một chuỗi các ký tự không có nguyên âm. #include #include int Check_Vowel (char); check_vowel(char); int main () {& nbsp; char s [100], t [100]; & nbsp; int c, d = 0; main() & nbsp; printf ("Nhập một chuỗi để xóa nguyên âm \ n"); & nbsp; Nhận (s);printf("Enter a string to delete vowels\n"); & nbsp; for (c = 0; s [c]! = '\ 0'; c ++) {& nbsp; & nbsp; if (Check_Vowel (s [c]) == 0) {& nbsp; & nbsp; // Nếu không phải là nguyên âm & nbsp; & nbsp; & nbsp; t [d] = s [c]; & nbsp; & nbsp; & nbsp; d ++; & nbsp; & nbsp;} & nbsp; }for (c = 0; s[c] != '\0'; c++)
{ & nbsp; t [d] = '\ 0';[d]
= '\0';C chương trình để loại bỏ các nguyên âm khỏi chuỗi
#include
{
char s[100], t[100];
int
c, d = 0;
gets(s);
if (check_vowel(s[c]) == 0) { // If not a vowel
t[d] = s[c];
d++;
}
}
& nbsp; strcpy (s, t); & nbsp; // Chúng tôi đang thay đổi chuỗi ban đầu. Đây là tùy chọn.strcpy(s, t); // We are changing initial string. This is optional.
& nbsp; printf ("Chuỗi sau khi xóa nguyên âm: %s \ n", s);printf("String after deleting vowels: %s\n", s);
& nbsp; return0;}return 0;
}
int Check_Vowel (char t) {& nbsp; if (t == 'a' || t == 'a' || t == 'e' || t == 'e' || t == 'i' | t == 'o' || t == 'o' || t == 'u' || t == 'u') & nbsp; & nbsp; return1;
check_vowel(char t)
{
if (t == 'a' || t == 'A' || t == 'e' || t == 'E' || t == 'i' || t == 'I' || t =='o' ||
t=='O' || t == 'u' || t == 'U')
return 1;
& nbsp; return0;}return 0;
}
int Check_Vowel (char t) {& nbsp; if (t == 'a' || t == 'a' || t == 'e' || t == 'e' || t == 'i' | t == 'o' || t == 'o' || t == 'u' || t == 'u') & nbsp; & nbsp; return1;
Đầu ra của chương trình:
#include#include#include
#include
#include
C mã lập trình bằng cách sử dụng con trỏint check_vowel(char);
& nbsp; int Check_vowel (char);()
{
char string[100], *temp, *p, ch,
*start;
& nbsp; main () {& nbsp; & nbsp; chuỗi char [100],*temp,*p, ch,*bắt đầu;printf("Enter a string\n");
gets(string);
& nbsp; & nbsp; & nbsp; printf ("Nhập chuỗi \ n"); & nbsp; & nbsp; getS (chuỗi);= string;
p = (char*)malloc(100);
& nbsp; & nbsp; & nbsp; temp = chuỗi; & nbsp; & nbsp; p = (char*) malloc (100);if( p == NULL )
{
printf("Unable to allocate memory.\n");
exit(EXIT_FAILURE);
}
& nbsp; & nbsp; if (p == null) & nbsp; & nbsp; {& nbsp; & nbsp; & nbsp; printf ("không thể phân bổ bộ nhớ. \ n"); & nbsp; & nbsp; & nbsp; Thoát (EXIT_FAILURE); & nbsp; & nbsp;}
& nbsp; & nbsp;= p;
Bắt đầu = P;while(*temp)
{
ch = *temp;
& nbsp; & nbsp; & nbsp; while (*temp) & nbsp; & nbsp; {& nbsp; & nbsp; & nbsp; ch =*temp;if ( !check_vowel(ch) )
{
*p = ch;
p++;
}
temp++;
}
*p = '\0';
& nbsp; & nbsp; & nbsp; & nbsp; if (! Check_vowel (ch)) & nbsp; & nbsp; & nbsp; {& nbsp; & nbsp; & nbsp; & nbsp; & nbsp;*p = ch; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; p ++; & nbsp; & nbsp; & nbsp; } & nbsp; & nbsp; & nbsp; TEMP ++; & NBSP; & nbsp;} & nbsp; & nbsp;*p = '\ 0';= start;
strcpy(string, pointer); /* If you wish to convert original string */
free(p);
& nbsp; & nbsp; & nbsp; p = start; & nbsp; & nbsp; strcpy (chuỗi, con trỏ);/ * nếu bạn muốn chuyển đổi chuỗi gốc */& nbsp; & nbsp; miễn phí (p);printf("String after removing vowel(s): \"%s\"\n", string);
& nbsp; & nbsp; & nbsp; printf ("Chuỗi sau khi loại bỏ nguyên âm: \"%s \ "\ n", chuỗi);return 0;
}
& nbsp; & nbsp; & nbsp; return0;}int check_vowel(char a)
{
if (a == 'a' || a == 'e' || a == 'i'
|| a == 'o' || a == 'u')
return 1;
else if (a == 'A' || a == 'E' || a == 'I' || a == 'O' || a ==
'U')
return 1;
else
return 0;
}