Error[8]: Undefined offset: 4, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述我试图通过将所有辅音放入不同的数组然后将第一个数组重新初始化为第二个数组来删除字符串的所有元音.之后,应该打印第一个数组,即只有辅音.我真的不确定问题出在哪里,我一直在看这个问题好三个小时,我已经厌倦了. #include <stdio.h>#include <stdlib.h>#include <string.h>int main(){ char str [100]; 我试图通过将所有辅音放入不同的数组然后将第一个数组重新初始化为第二个数组来删除字符串的所有元音.之后,应该打印第一个数组,即只有辅音.我真的不确定问题出在哪里,我一直在看这个问题好三个小时,我已经厌倦了.

#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 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;}
解决方法 您的char初始化应该是这样的

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 – 删除字符串中的元音.我究竟做错了什么?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
c – 删除字符串中的元音.我究竟做错了什么?_C_内存溢出

c – 删除字符串中的元音.我究竟做错了什么?

c – 删除字符串中的元音.我究竟做错了什么?,第1张

概述我试图通过将所有辅音放入不同的数组然后将第一个数组重新初始化为第二个数组来删除字符串的所有元音.之后,应该打印第一个数组,即只有辅音.我真的不确定问题出在哪里,我一直在看这个问题好三个小时,我已经厌倦了. #include <stdio.h>#include <stdlib.h>#include <string.h>int main(){ char str [100]; 我试图通过将所有辅音放入不同的数组然后将第一个数组重新初始化为第二个数组来删除字符串的所有元音.之后,应该打印第一个数组,即只有辅音.我真的不确定问题出在哪里,我一直在看这个问题好三个小时,我已经厌倦了.

#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 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;}
解决方法 您的char初始化应该是这样的

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 – 删除字符串中的元音.我究竟做错了什么?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1216767.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-05
下一篇 2022-06-05

发表评论

登录后才能评论

评论列表(0条)

保存