gpt4 book ai didi

c++ - 在 Visual Studio 2013 中随时调试程序执行时的情况

转载 作者:行者123 更新时间:2023-11-30 19:44:29 26 4
gpt4 key购买 nike

我是编程和 Visual Studio 的新手。目前我正在使用 Visual Studio 2013,我想知道如何在启动本地 Windows 调试器后随时开始调试。在这段代码中,我想在输入要搜索的号码后开始调试。这是代码。

#include<stdio.h`
#include<math.h>
#pragma warning (disable : 4996)
#define MAX_SIZE 100
#define SWAP(x,y,t) ( (t) = (x), (x) = (y), (y) = (t))
int size_check(int n)
{
int a;
a = n;
if (a < 1 || a>100)
{
(a < 1) ? printf("\nSize can't be smaller than 1 , please try again!") : printf("\nmax size allowed is 100, pleasetry again");
printf("\nEnter the length of array :\t ");
scanf("%d", &a);
return(size_check(a)); /*or a = size_check(a)*/

}
return a;
}

void sort_array(int list[], int n)
{
int i, j, temp;

for (i = 0; i < n - 1; i++)

for (j = i + 1; j < n;j++)

if (list[i]>list[j])
{
SWAP(list[i], list[j], temp);

}
}

void b_search(int list[], int sno,int a)
{
int left, right, middle, i=1, n=a-1;
left = 0;
right = n;

while (left != right)
{
middle =( (left + right) / 2);

if (sno == list[middle])
{
printf("\nSearched number is present in array at %d ",middle);
break;
}


if (sno < list[middle])
{
right = middle - 1;
}

else
{
left = middle + 1;
}
}


if (left == right || sno != list[middle])
printf("Searched number is not present in array!");
}

void main()
{
int n, i ,sno,list[MAX_SIZE];

printf("Enter the length of array :\t ");
scanf("%d", &n);
n=size_check(n);

for (i = 0; i < n; i++)
{
printf("Enter the %d element of array:\t",i);
scanf("%d", &list[i]);
}

sort_array(list, n);

printf("\nThe shorted array :");

for (i = 0; i < n; i++)
{
printf("\n%d",list[i]);

}

printf("\nEnter the number you want to search in array:\t");
scanf("%d", &sno);
b_search(list, sno, n);


getch();

}

最佳答案

启动调试器后,在 Visual Studio 中(见下文):

Start Debugger

您已进入 main 方法,可以使用 F11(下一步)、F10(下一行)或 F5(下一个断点)进行导航

要设置这些断点,您只需单击编写的代码行旁边的:

enter image description here

因此,设置完这些后,您就可以启动程序,在以下位置设置断点:

 scanf("%d", &a);
return(size_check(a)); /*or a = size_check(a)*/

}
return a;
}

然后查看数组如何填充,只需使用 F11 浏览代码:)

关于c++ - 在 Visual Studio 2013 中随时调试程序执行时的情况,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28036851/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com