帮我调试这段代码。 [英] Help me to debug this code.

查看:70
本文介绍了帮我调试这段代码。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <stdio.h>
#include <string.h>

int main()
{   int t;
    scanf("%d",&t);

    while(t--)
    {
     char s1[100000],s2[100000];
    long int l;
    scanf("%s",s1);
    l=strlen(s1);
    
    for(int i=0;i<l;i++){
       s2[l-1-i]=s1[i];}

    for(int i=0;i<l;i++){
        
        if(s1[i]+s2[i]<=218)
            s1[i]=s1[i]+s2[i]-96;
        else
            s1[i]=s1[i]+s2[i]-122;
    }
    printf("%s\n",s1);



}
return 0;

}





我的尝试:



plzzz ....上传调试此代码的视频,向我解释如何调试。



What I have tried:

plzzz.... upload video of debugging this code to explain me how to debug.

推荐答案

将其加载到Visual Studio中并在Debug模式下构建。在Visual Studio编辑器中,单击 main 之后第一行旁边的窗口边框。您应该在边框中看到一个红色斑点,表示该行上的断点。按F5键,程序将加载到调试器中并停在该行。您现在可以逐行逐步执行此操作并在检查所有变量时进行检查。 Visual Studio帮助页面包含您需要的所有信息。
Load it into Visual Studio and build in Debug mode. In the Visual Studio editor click on the window border next to the first line after main. You should see a red blob in the border indicating a breakpoint on that line. Press F5 and the program will be loaded into the debugger and stop at that line. You can now step through it line by line and inspect all variables as you go through. The Visual Studio help pages have all the information you need.


您的代码看起来有些奇怪。您应该为变量使用更长的名称,将数字命名为常量和注释,以及您要执行的操作。



通常情况下,在有问题的代码行中进行更多步骤和更多调试输出会更好。如果一切正常就可以删除。



一个问题是:

Your code looks somehow strange. You should use longer names for the variables, name the numbers as constants and comments, what you do.

Often is it better to make more step and more debug output in problematic code lines. If all works it can get removed.

One problem is:
s1[i]+s2[i];

因为它可以在char数据类型中溢出。更好的应该是

because it can overflow in a char data type. Better should be

int c = s1[i]+s2[i];
char out = (char) (c - 122);//calc with int, casting the result to char


引用:

plzzz ....上传调试此代码的视频解释我如何调试。

plzzz.... upload video of debugging this code to explain me how to debug.



不,我们知道调试,你是学习它的人。

你第一次问这个问题时已经得到了答案。

Nota:视频是您的解释。


No, we know debugging, you are the one that to learn it.
You already got answers first time you asked this question.
Nota: the video is your explanation.


这篇关于帮我调试这段代码。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆