方法一(输出的字符前后无空格):
#include <stdio.h>#include <string.h>void ycopy(char x[], char y[]); //定义复制函数int main(){char a[20]="", b[20]="";//字符串初始化gets(a);//输入字符串ycopy(a, b);//调用复制函数puts(b);//输出复制后的字符串return 0;}//元音复制函数void ycopy(char x[], char y[]){int m, i, j;m=(int)strlen(x);for (i=0, j=0; i<m; i++){if (x[i]=='a'||x[i]=='A')y[j++]=x[i];else if (x[i]=='e'||x[i]=='E')y[j++]=x[i];else if (x[i]=='i'||x[i]=='I')y[j++]=x[i];else if (x[i]=='o'||x[i]=='O')y[j++]=x[i];else if (x[i]=='u'||x[i]=='U')y[j++]=x[i];}y[j] = '\0';}
在VS下,需将源文件的gets做些修改:
#include <stdio.h>#include <string.h>void ycopy(char x[], char y[]); //定义复制函数int main(){char a[20] = "", b[20] = "";//字符串初始化gets_s(a, 20);//输入字符串ycopy(a, b);//调用复制函数puts(b);//输出复制后的字符串return 0;}//元音复制函数void ycopy(char x[], char y[]){int m, i, j;m = (int)strlen(x);for (i = 0, j = 0; i < m; i++){if (x[i] == 'a' || x[i] == 'A')y[j++] = x[i];else if (x[i] == 'e' || x[i] == 'E')y[j++] = x[i];else if (x[i] == 'i' || x[i] == 'I')y[j++] = x[i];else if (x[i] == 'o' || x[i] == 'O')y[j++] = x[i];else if (x[i] == 'u' || x[i] == 'U')y[j++] = x[i];}y[j] = '\0';}
方法二(输出的字符前后无空格):
#include <stdio.h>#include <string.h>void input(char st[]); //定义输入函数void output(char st[]); //定义输出函数void letter(char x[], char y[]); //定义元音复制函数int main(){char s1[20]="", s2[10]="";//字符串初始化input(s1);//调用输入函数letter(s1, s2); //调用元音复制函数output(s2);//调用输出函数return 0;}//输入函数void input(char st[]){printf("Please enter string:");gets(st);}//元音复制函数void letter(char x[], char y[]){int n=(int)strlen(x);int i,j;for (i=0, j=0; i<n; (x[i]=='a'||x[i]=='e'||x[i]=='i'||x[i]=='o'||x[i]=='u'||x[i]=='A'||x[i]=='E'||x[i]=='I'||x[i]=='O'||x[i]=='U') ? y[j++]=x[i++] : i++);y[j]='\0';}//输出函数void output(char st[]){printf("The final string:%s\n", st);}
在VS下,需将源文件的gets做些修改:
#include <stdio.h>#include <string.h>void input(char st[]); //定义输入函数void output(char st[]); //定义输出函数void letter(char x[], char y[]); //定义元音复制函数int main(){char s1[20] = "", s2[10] = "";//字符串初始化input(s1);//调用输入函数letter(s1, s2); //调用元音复制函数output(s2);//调用输出函数return 0;}//输入函数void input(char st[]){printf("Please enter string:");gets_s(st, 20);}//元音复制函数void letter(char x[], char y[]){int n =(int)strlen(x);int i, j;for (i = 0, j = 0; i < n; (x[i] == 'a' || x[i] == 'e' || x[i] == 'i' || x[i] == 'o' || x[i] == 'u' || x[i] == 'A' || x[i] == 'E' || x[i] == 'I' || x[i] == 'O' || x[i] == 'U') ? y[j++] = x[i++] : i++);y[j] = '\0';}//输出函数void output(char st[]){printf("The final string:%s\n", st);}
方法一变形(输出的字符前后有空格):
#include <stdio.h>#include <string.h>void ycopy(char x[], char y[]); //定义复制函数int main(){char a[20]="", b[20]="";//字符串初始化gets(a);//输入字符串ycopy(a,b); //调用复制函数puts(b); //输出复制后的字符串return 0;}//元音复制函数void ycopy(char x[], char y[]){int m, i, j;m=(int)strlen(x);for (i=0, j=0; i<m; i++){if (x[i]=='a'||x[i]=='A')y[j++]=x[i];else if (x[i]=='e'||x[i]=='E')y[j++]=x[i];else if (x[i]=='i'||x[i]=='I')y[j++]=x[i];else if (x[i]=='o'||x[i]=='O')y[j++]=x[i];else if (x[i]=='u'||x[i]=='U')y[j++]=x[i];else y[j++]=' ';}y[j] = '\0';}
在VS下,需将源文件的gets做些修改:
#include <stdio.h>#include <string.h>void ycopy(char x[], char y[]); //定义复制函数int main(){char a[20] = "", b[20] = "";//字符串初始化gets_s(a, 20);//输入字符串ycopy(a, b); //调用复制函数puts(b); //输出复制后的字符串return 0;}//元音复制函数void ycopy(char x[], char y[]){int m, i, j;m =(int)strlen(x);for (i = 0, j = 0; i < m; i++){if (x[i] == 'a' || x[i] == 'A')y[j++] = x[i];else if (x[i] == 'e' || x[i] == 'E')y[j++] = x[i];else if (x[i] == 'i' || x[i] == 'I')y[j++] = x[i];else if (x[i] == 'o' || x[i] == 'O')y[j++] = x[i];else if (x[i] == 'u' || x[i] == 'U')y[j++] = x[i];else y[j++] = ' ';}y[j] = '\0';}
方法二变形(输出的字符前后有空格):
#include <stdio.h>#include <string.h>void input(char st[]); //定义输入函数void output(char st[]); //定义输出函数void letter(char x[], char y[]); //定义元音复制函数int main(){char s1[20] = "", s2[10] = "";//字符串初始化input(s1);//调用输入函数letter(s1, s2); //调用元音复制函数output(s2);//调用输出函数return 0;}//输入函数void input(char st[]){printf("Please enter string:");gets(st);}//元音复制函数void letter(char x[], char y[]){int n = (int)strlen(x);int i, j;for (i = 0, j = 0; i < n; (x[i] == 'a' || x[i] == 'e' || x[i] == 'i' || x[i] == 'o' || x[i] == 'u' || x[i] == 'A' || x[i] == 'E' || x[i] == 'I' || x[i] == 'O' || x[i] == 'U') ? y[j++] = x[i++] : i++);y[j] = '\0';}//输出函数void output(char st[]){int i = 0;printf("The final string:");for (i = 0; i < (int)strlen(st); i++){printf("%c ", st[i]);}}
在VS下,需将源文件的gets做些修改:
#include <stdio.h>#include <string.h>void input(char st[]); //定义输入函数void output(char st[]); //定义输出函数void letter(char x[], char y[]); //定义元音复制函数int main(){char s1[20] = "", s2[10] = "";//字符串初始化input(s1);//调用输入函数letter(s1, s2); //调用元音复制函数output(s2);//调用输出函数return 0;}//输入函数void input(char st[]){printf("Please enter string:");gets_s(st, 20);}//元音复制函数void letter(char x[], char y[]){int n = (int)strlen(x);int i, j;for (i = 0, j = 0; i < n; (x[i] == 'a' || x[i] == 'e' || x[i] == 'i' || x[i] == 'o' || x[i] == 'u' || x[i] == 'A' || x[i] == 'E' || x[i] == 'I' || x[i] == 'O' || x[i] == 'U') ? y[j++] = x[i++] : i++);y[j] = '\0';}//输出函数void output(char st[]){int i = 0;printf("The final string:");for (i = 0; i < (int)strlen(st); i++){printf("%c ", st[i]);}}