Guidelines for working with Microsoft Visual Studio 6
Create a new Project
Select Project Type
Select Project Type
Create Executable File
Inserting a breakpoint
Press right mouse button and select “Insert Breakpoint”
Stopping at a Breakpoint
The “Watch” window will show the values of the variables
Stepping Over
“Step over” and check the values in the “Watch” window
Run to Cursor
“Run to cursor” will run till the current cursor position
Checking a value of a variable
Checking a value of a variable
Choose “Add Watch” to a variable to the “Watch” window
Factorial
#include <stdio.h>
int main(void) {int i,n, fact=1;printf("Enter a number: ");scanf("%d", &n);
for (i =1; i<=n; i++){fact*=i;
}printf ("\nThe functorial is: %d\n", fact);return 0;
}
Stepping through a Loop
Errors
• Syntax errors – caught by compiler• Run-time errors - seen during program execution.• Reasons for run-time errors:
– Infinite loops – Division by zero – Many more …
• Important Termination Commands:– Unix: <Cntrl>-C – MS-DOS: <Cntrl>-C or <Cntrl>-break
Compilation Errors Example
Run Time Error Example
Don’t try this at home!!!
Infinite Loop
Don’t try this at home!!!
Use <Cntrl> C to terminate the execution
Code and Compilation Examples
Printing Numbers
#include <stdio.h>
int main(void) {
int i;
for(i=0; i<100; i++){
printf("%d\n", i);
}
return 0;
}
Printing Numbers#include <stdio.h>int main(void){
int i,j;for(i=0; i<20; i++){
for(j=0;j<20;j++){printf("%d ", i);
}printf("\n");
}return 0;
}