#include <stdio.h>#include <stdlib.h>#include <string.h>int main(){ char str [100]; char garbage[100]; int loopcondition = 0,j = 0,k = 0; int userinput; char a = "a",e = "e",i = "i",o = "o",u = "u"; printf("!!!Hello World!!! Please type in a string from which I can remove all the vowels:\n"); //This program is supposed to take in a string and then delete all the vowels gets(str); //gets user input userinput = strlen(str); //makes userinput equal to the length of the string while(loopcondition < userinput) //the loop runs until the condition is no longer smaller than the input { loopcondition++; //incrementation of condition if(str[j] != a || e || i || o || u) // this should check wether the current position in the array is a vowel { garbage[k] = str[j] ; //if it's not the it puts the current character into the garbage array k++; //iteration of the garbage array position }; j++; //incrementation of string array position }; garbage[k] = '解决方法 您的char初始化应该是这样的char a = 'a',e = 'e',i = 'i',o = 'o',u = 'u';'; strcpy (str,garbage ); //this copIEs the string?!?! aka reinitiliazing array variable printf("%s",str); return 0;}
if(str[j] != a || e || i || o || u)
请记住,双引号(“”)用于字符串文字,单引号(”)用于字符文字.
然后,
if( (str[j] != a) && (str[j] != e) && (str[j] != i).......//so on
这不是你在c中使用逻辑OR(||)运算符的方式.链接是不可能的.你必须分别检查每个条件.就像是
但是,在我看来,如果你改变逻辑以使用开关盒,它将是一个更好的设计.
哦,最好使用int main(voID),这在标准中是推荐的.
总结以上是内存溢出为你收集整理的c – 删除字符串中的元音.我究竟做错了什么?全部内容,希望文章能够帮你解决c – 删除字符串中的元音.我究竟做错了什么?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)