当我在函数中调用一个函数时,它会跳过代码并终止程序
When I call a function within a function it skips code and terminates program?
这是一个大程序。我去掉了不必要的代码。我只留下了一个关键函数
当我在任何函数中调用ss();
时,函数将控制权交还给main()
而不接受字符串。如果我不使用函数来接受字符串,代码就会工作。我看不出有什么问题。
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<ctype.h>
void ss();
void casechange();
using namespace std;
char str[100];
int main (){
int choice;
cout<<"Make a choice"<<endl;
cout<<"Press 1 to change the case of alphabets"<<endl;
cout<<"Press 2 to count number of vowels"<<endl;
cout<<"Press 3 to check if entered string is a palindrome or not"<<endl;
cout<<"Press 4 to reverse a string"<<endl;
cout<<"Press 5 to count number of words"<<endl;
cin>>choice;
switch(choice){
case 1: casechange();
break;
case 2: vowelcount();
break;
case 3:pal();
break;
case 4: rev();
break;
case 5: wordcount();
break;
default: cout<<"Wrong choice"<<endl;
}
return 0;
}
void casechange(){
ss();
for(int i=0;str[i]!=' ';i++)
{
if(isupper(str[i]))
str[i]=tolower(str[i]);
else str[i]=toupper(str[i]);
}
puts(str);
}
void ss()
{
cout<<"Enter a string"<<endl;
gets(str);
}
注。我正在使用代码块。
您要求用户做出选择。用户输入数字和 enter
。然后你读一个字。enter
仍然坐在缓冲中。当涉及到gets
时,它将其作为空字符串读取。
还请注意所有关于IO, gets
等的评论
相关文章:
- 如何将 c++ get 函数代码转换为 opencv 算法中使用的 python
- 修改链表主函数代码,用户将在其中输入节点的索引和数据以及正确的消息
- 是否可以像这样编写c malloc函数代码
- 函数范围的静态变量如何导致与共享库中函数代码的未来使用不兼容
- 如何将C++ lambda 函数代码转换为 C#?
- 该构造函数代码如何将指针作为参数
- 调用C++具有复杂参数和复杂返回类型的函数 C 代码
- "_FCbuild"不能用作函数 - C/C++ 代码错误
- 复制赋值和复制构造函数(代码C++的差异)
- 反向链表的递归函数(代码段说明)
- 当满足条件时,是否可以在 GLSL 着色器中回调 C/C++ 函数/代码
- 在构造函数代码之前禁用默认类成员初始化
- 以下移动构造函数代码安全吗?
- C++构造函数代码..这叫什么
- 如何更改SWIG生成的CSHARP文件中的构造函数代码
- 找不到当前函数(代码::块)C++的边界
- 使用模板进行 C++ 函数代码泛化
- 编写此指针函数代码的长格式方法是什么
- C++某些构造函数代码之间的区别
- 错误C2668从站点对重载函数代码的调用不明确http://h264bitstream.sourceforge.net/