I'm new to programming and visual studio .currently i'm using visual studio 2013 and i want to know how can i start debugging at any point after i have started local windows debugger. In this code i want to start debugging after entering the number to be searched.Here is the code.
#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();
}
So in Visual Studio after you have started the Debugger (see below):
You entered at the main method where you can navigate using F11 (Next Step), F10 (Next Line) or F5 (Next Breakpoint)
For setting these Breakpoints you simply have to click next to the code-line written:
So after setting these you can just start you progam, set a breakpoint at:
scanf("%d", &a);
return(size_check(a)); /*or a = size_check(a)*/
}
return a;
}
And then see how your array gets filled afterwards, just use F11 to go through your code :)