CE求助
  • 板块学术版
  • 楼主Whr___114514
  • 当前回复6
  • 已保存回复8
  • 发布时间2025/1/10 08:10
  • 上次更新2025/1/10 16:35:14
查看原帖
CE求助
1583675
Whr___114514楼主2025/1/10 08:10

P5733自动修正


上一次做用了strupr,CE了,听从了大佬的意见:Linux用不了strupr。这回定了一个函数,在DevC++中调试成功了,然而提交后……

/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){
      |             ~~~~~~~^

代码如下:

#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;
}
2025/1/10 08:10
加载中...