社区讨论

为什么编译错误?

题目总版参与者 5已保存回复 9

讨论操作

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

当前回复
9 条
当前快照
1 份
快照标识符
@mi4epotq
此快照首次捕获于
2025/11/18 18:04
4 个月前
此快照最后确认于
2025/11/18 18:04
4 个月前
查看原帖
我在Dev-C++里面编译无错误,结果也是对的,怎么一上传到洛谷就编译错误了?
难道是malloc函数的问题?
为什么gets函数报错?
源代码:
···cpp
CPP
#include<iostream>
#include<string.h>
#include<stdlib.h> 
#include<cstdio>
using namespace std;
int main()
{
    char a[11],b[1000001];
    int i,j,s=0,c,t;
    bool x,z=true;
    cin>>a;
    gets(b);
    gets(b);
    char *p=strupr(a);
    char *q=strupr(b);
    char *a1=(char *)malloc(sizeof(char)*(strlen(a)+1));
    strcpy(a1,p);
    char *b1=(char *)malloc(sizeof(char)*(strlen(b)+1));
    strcpy(b1,q);
    int m=strlen(b1),n=strlen(a1);
    for(i=0;i<m;i++)
    {
        x=true;
        j=0;
        t=i;
        if(b1[i]==' ') continue;
        while(j<n)
        {
            if(b1[i]!=a1[j]){
                x=false;
                break;
            }
            i++;
            j++;
        }
        if(x==true){
            s++;
        }
        if((z==true)&&(x==true)){
            z=false;
            c=t;
        }
    }
    if(s==0) cout<<"-1";
        else cout<<s<<" "<<c;
    return 0;
}
··· 对了,题目是“统计单词数”
错误信息:
tmp/tmptqf9xyq5.cpp: In function ‘int main()’:
/tmp/tmptqf9xyq5.cpp:12:2: warning: ‘char* gets(char*)’ is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations]
gets(b);
^ /tmp/tmptqf9xyq5.cpp:12:8: warning: ‘char* gets(char*)’ is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations]
gets(b);
^ /tmp/tmptqf9xyq5.cpp:13:2: warning: ‘char* gets(char*)’ is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations]
gets(b);
^ /tmp/tmptqf9xyq5.cpp:13:8: warning: ‘char* gets(char*)’ is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations]
gets(b);
^ /tmp/tmptqf9xyq5.cpp:14:18: error: ‘strupr’ was not declared in this scope
char *p=strupr(a);
^

回复

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

正在加载回复...