社区讨论

CE求助

学术版参与者 3已保存回复 8

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
6 条
当前快照
1 份
快照标识符
@m5q068as
此快照首次捕获于
2025/01/10 08:12
去年
此快照最后确认于
2025/11/04 11:49
4 个月前
查看原帖
P5733自动修正

上一次做用了strupr,CE了,听从了大佬的意见:Linux用不了strupr。这回定了一个函数,在DevC++中调试成功了,然而提交后……
CPP
/tmp/compiler_3r2t8zsq/src: 在函数‘int main()’中:
/tmp/compiler_3r2t8zsq/src:13:9: 错误:cannot bind non-const lvalue reference of type ‘char*&’ to an rvalue of type ‘char*’
   13 |  strupr(a);
      |         ^
/tmp/compiler_3r2t8zsq/src:4:20: 附注:  初始化‘void strupr(char*&)’的实参 1
    4 | void strupr(char* &e){
      |             ~~~~~~~^

代码如下:
CPP
#include<iostream>
#include<cstring>
using namespace std;
void strupr(char* &e){
	int b=strlen(e);
	for(int i=0;i<b;i++){
		if(e[i]>='a'&&e[i]<='z') e[i]+=32;
	}
}
int main(){
	char a[105];
	cin>>a;
	strupr(a);
	cout<<a;
	return 0;
}

回复

8 条回复,欢迎继续交流。

正在加载回复...