Guidelines for working with Microsoft Visual Studio 6
Create a new Project
Select Project Type
Create New File
Write the Code
Stage 2: Compile
Create Executable File
Stage 3: Execute
Execution Window
Inserting a breakpoint Press right mouse button and select “Insert Breakpoint”
Start Debugging
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
Choose “Add Watch” to a variable to the “Watch” window
Factorial #include 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: -C –MS-DOS: -C or -break
Compilation Errors Example
Run Time Error Example Don’t try this at home!!!
Infinite Loop Don’t try this at home!!! Use C to terminate the execution
Code and Compilation Examples
Printing Numbers #include int main(void) { int i; for(i=0; i<100; i++){ printf("%d\n", i); } return 0; }
Printing Numbers #include 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; }