markdown 在CS50 IDE中调试C语言

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 在CS50 IDE中调试C语言相关的知识,希望对你有一定的参考价值。

Debugging in C in CS50 IDE:

I. If the error occur when compiling, use "help50" to get more hint about the error.

Use help50 like this:

help50 make program_name

II. eprintf

Put "eprintf" in certain line of the code, so we know that a certain part of the code was excecuted.

Example code:

	int x = get_int();
	eprintf("Integer obtained!\n");
	
So when the program runs, the eprintf will tell you at what line of code this was done:

program_name.c:8: Integer Obtained!

So it also tells you the line number which is 8.

III. Debug50

So when a program does compile without error, but the output is not right, we use debug50.

First, we set a break point for the program, usually is on the line where the "main" is.

To set a break point, we put the cursor to the left of the "main" line, one click and a red dot will appear, that means it's the break point.
So when the program runs, it will stop at the break point line.

You can double click on the red break point to make it go away.

To run using Debug50:

debug50 ./program_name

when this runs, the program will stop at the break point, and on the right a window will pop up.

In this window, it tells us what functions we are in, and what variables we have at that point, the value and type of that variable.

On top of this window, there are some keys we can use to control the running of the program.

1. Rusme: which will let the program run to the end and ignoring any break points. Use this when we no longer want to debug.
2. Step over: let the program execute the next line. So it will execute the next line and then stop at the next line after that.
3. Step into: if there is a block of code, like a "if" with brackets, we can step into the brackets, and see how codes execute inside the brackets. Or if it's a function, also can step into it.
4. Step out: to step out of the block of code or function that you have stepped into before.

So each time you step over a line, or step into a code block, take a look at the information about the functions involved in each step, and also how the value or type of the variables changed with the execution of each line. You can also change the value of a variable at a certain line, to see how the program behave. That would help us to find out where the problem might be.

以上是关于markdown 在CS50 IDE中调试C语言的主要内容,如果未能解决你的问题,请参考以下文章

用C语言编程,哪个IDE最好?

c++最好的开发工具

1.4 C语言集成开发环境(IDE)

制作 cs的 config用c语言么

如何在windows下搭建c语言开发环境,不使用ide。

2020牛客寒假算法基础集训营5.C——C语言IDE超级大模拟