Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/159.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 任何情况下都会出现意外输出。我的解决方案有什么问题?_C++_String - Fatal编程技术网

C++ 任何情况下都会出现意外输出。我的解决方案有什么问题?

C++ 任何情况下都会出现意外输出。我的解决方案有什么问题?,c++,string,C++,String,问题131A- 我的解决方案没有按问题要求执行,而是返回输入的相同字符串。我的解决方案有什么问题 我的解决方案: #include<iostream> #include<cstring> using namespace std; int i,a; char input[101]; int main() { cin>>input; a=0; for(i=0;input[i]!=NULL;i++) //To find number of u

问题131A- 我的解决方案没有按问题要求执行,而是返回输入的相同字符串。我的解决方案有什么问题

我的解决方案:

#include<iostream>
#include<cstring>
using namespace std;
int i,a;
char input[101];
int main()
{
    cin>>input;
    a=0;
    for(i=0;input[i]!=NULL;i++) //To find number of uppercase letters.
    {
        if(isupper(input[i]))
        a++;
    }
    if((a==strlen(input))|((a==(strlen(input)-1))&(islower(input[0])))) //To check for accidental pressing of Caps Lock(Words like Jingle or jINGLE.).
    {
        toupper(input[0]);
        for(i=1;input[i]!=NULL;i++)
        {
            tolower(input[i]);
        }
        cout<<input;
    }
    else
    cout<<input;
}
#包括
#包括
使用名称空间std;
int i,a;
字符输入[101];
int main()
{
cin>>输入;
a=0;
for(i=0;输入[i]!=NULL;i++)//查找大写字母数。
{
if(isupper(输入[i]))
a++;
}
如果((a==strlen(input))|((a==(strlen(input)-1))&(islower(input[0]))//检查是否意外按下了大写锁定键(如叮当声或叮当声)。
{
toupper(输入[0]);
对于(i=1;输入[i]!=NULL;i++)
{
tolower(输入[i]);
}
库特
不将
input[0]
更改为大写,它返回与
input[0]
等效的大写字母

试一试

取而代之的是(其他每一个touper/tolower调用都是如此)

不将
input[0]
更改为大写,它返回与
input[0]
等效的大写字母

试一试

取而代之的是(其他每一个touper/tolower调用都是如此)

不将
input[0]
更改为大写,它返回与
input[0]
等效的大写字母

试一试

取而代之的是(其他每一个touper/tolower调用都是如此)

不将
input[0]
更改为大写,它返回与
input[0]
等效的大写字母

试一试

相反(对于其他toupper/tolower调用也是如此)。

char-toupper(char)
char-tolower(char)
只返回转换后的字符,而不修改传递的字符(需要引用或指针使用)。请使用:

input[0] = toupper(input[0]);
for(i=1;input[i]!=NULL;i++)
{
    input[i] = static_cast<char> ( tolower( static_cast<unsigned char>(input[i]) ) );
}
cout<<input;
input[0]=toupper(input[0]);
对于(i=1;输入[i]!=NULL;i++)
{
输入[i]=静态_cast(tolower(静态_cast(输入[i])));
}
cout
char-toupper(char)
char-tolower(char)
仅返回转换后的字符,不修改传递的字符(需要使用引用或指针)。请改用:

input[0] = toupper(input[0]);
for(i=1;input[i]!=NULL;i++)
{
    input[i] = static_cast<char> ( tolower( static_cast<unsigned char>(input[i]) ) );
}
cout<<input;
input[0]=toupper(input[0]);
对于(i=1;输入[i]!=NULL;i++)
{
输入[i]=静态_cast(tolower(静态_cast(输入[i])));
}
cout
char-toupper(char)
char-tolower(char)
仅返回转换后的字符,不修改传递的字符(需要使用引用或指针)。请改用:

input[0] = toupper(input[0]);
for(i=1;input[i]!=NULL;i++)
{
    input[i] = static_cast<char> ( tolower( static_cast<unsigned char>(input[i]) ) );
}
cout<<input;
input[0]=toupper(input[0]);
对于(i=1;输入[i]!=NULL;i++)
{
输入[i]=静态_cast(tolower(静态_cast(输入[i])));
}
cout
char-toupper(char)
char-tolower(char)
仅返回转换后的字符,不修改传递的字符(需要使用引用或指针)。请改用:

input[0] = toupper(input[0]);
for(i=1;input[i]!=NULL;i++)
{
    input[i] = static_cast<char> ( tolower( static_cast<unsigned char>(input[i]) ) );
}
cout<<input;
input[0]=toupper(input[0]);
对于(i=1;输入[i]!=NULL;i++)
{
输入[i]=静态_cast(tolower(静态_cast(输入[i])));
}

cout
toupper()
tolower()
不更改它们的参数,而是返回更改后的字符。必须编写
input[i]=toupper(input[i])
。然后不应使用位运算符执行这些条件检查。请改用
|
&

toupper()
tolower
不要更改它们的参数,而是返回更改后的字符。必须编写
input[i]=toupper(input[i])
。然后不应使用位运算符进行这些条件检查。请改用
|
&

toupper()
tolower()
不要更改它们的参数,而是返回更改后的字符。必须编写
input[i]=toupper(input[i])
。然后不应使用位运算符进行这些条件检查。请改用
|
&

toupper()
tolower()
不更改参数,但返回更改后的字符。您必须编写
input[i]=toupper(input[i])
。那么你不应该使用位运算符进行这些条件检查。使用
|
&
来代替。

你不喜欢空字符吗?的确。不要使用
null
作为
'\0'
。从技术上讲
null
甚至不能保证值为0,只能变成
(void*)0
如果在指针上下文中使用。
|
|
?小心。如果((a==strlen(input))|((a==(strlen(input)-1))和(islower(input[0]))是什么
做什么?你确定你想按位
&
而不是逻辑
&
吗?你不喜欢空字符吗?的确。不要像
'\0'
那样使用
null
。从技术上讲
null
甚至不能保证值为0,只能变成
(void*)0
如果在指针上下文中使用。
|
|
?小心。如果((a==strlen(input))|((a==(strlen(input)-1))和(islower(input[0]))是什么
做什么?你确定你想按位
&
而不是逻辑
&
吗?你不喜欢空字符吗?的确。不要像
'\0'
那样使用
null
。从技术上讲
null
甚至不能保证值为0,只能变成
(void*)0
如果在指针上下文中使用。
|
|
?小心。如果((a==strlen(input))|((a==(strlen(input)-1))和(islower(input[0]))是什么
做什么?你确定你想按位
&
而不是逻辑
&
吗?你不喜欢空字符吗?的确。不要像
'\0'
那样使用
null
。从技术上讲
null
甚至不能保证值为0,只能变成
(void*)0
如果在指针上下文中使用。
|
|
?小心。如果((a==strlen(input))|((a==(strlen(input)-1))和(islower(input[0]))
正在做什么?您确定要按位
而不是逻辑