麻烦帮忙看一下为什么错谢谢

P5705 【深基2.例7】数字反转

T___Y @ 2022-08-01 12:56:17

#include<string.h>
int main()
{
    char a[6];
    scanf("%s",a);
    for(int i=strlen(a);i>0;i--)
    printf("%c",a[i]);
    return 0;
}

把strlen(a)改成stelen(a)-1,后面改成i>=0就对了 不理解为什么


by Unknown___Error @ 2022-08-01 12:59:54

下标0开始啊


by vdfes @ 2022-08-01 13:00:08

@T___Y 字符数组的读入默认从0开始,字符串也一样


by Unknown___Error @ 2022-08-01 13:00:18

@T___Y 字符串就是个字符数组


by Unknown___Error @ 2022-08-01 13:00:46

还有你这缩进清奇


by Andy_AC @ 2022-08-11 19:48:11

#include <bits/stdc++.h>
using namespace std;
string a;
int main(){
    cin>>a;
    reverse(a.begin(),a.end());
    cout<<a<<endl;
    return 0;
}

by kitty2022 @ 2022-08-19 10:43:47

@T___Y 下标从0开始


by kitty2022 @ 2022-08-19 10:44:46

@T___Y for循环后面要加大括号


|