UrbanPro

Learn C Language from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

How do I trace C programs in Turbo C?

Asked by Last Modified  

Follow 5
Answer

Please enter your answer

Computer Science

First of all goto C drive then program files then turbo c folder then open bin folder and search what program u want
Comments

Advance Excel And VBA Training

Turbo Debugger for Windows Introduction This document serves as a tutorial and reference for using Turbo Debugger for Windows (TDW). It is divided in two parts: the first part is a tutorial that introduces you to the basic features of TDW and debugging techniques needed to debug a program; the second...
read more
Turbo Debugger for Windows Introduction This document serves as a tutorial and reference for using Turbo Debugger for Windows (TDW). It is divided in two parts: the first part is a tutorial that introduces you to the basic features of TDW and debugging techniques needed to debug a program; the second part is a reference to the different debugging commands available in TDW. The document assumes you have a basic knowledge of using Turbo C for Windows and programming in the C language. Tutorial In this tutorial you will learn to the following debugging concepts: • Running and stopping program execution. • Examining the contents of program variables. • Looking at complex data objects, like arrays and structures. • Changing the value of variables. The tutorial uses a demo C program, called TDDEMO1.C to introduce you to TDW. As you read through this tutorial, you are advised to apply the techniques presented to the demo program. This will enable you to gain a better understanding of the debugger and the debugging process in general. The Demo program (TDDEMO1) The demo program, by itself, is not meant to be particularly useful; some of its code and data structures exist solely to show TDW's capabilities. The program implements a primitive calculator that performs the basic arithmetic operations of addition, subtraction, multiplication and division on integers. The program prompts the user for two integer numbers. It then performs the arithmetic operations on the numbers and prints out the result. TDDEMO1.C. #include "stdio.h" struct integerpair{ int x; int y; }; typedef struct integerpair IntegerPair; int Add(int A,int B); int Subtract(int A,int B); float Divide(int A,int B); int Multiply(int A,int B); void InitPairs(IntegerPair pairs[]); void PrintPairs(IntegerPair pairs[]); void main(){ IntegerPair pairs[20]; int A, B, sum, diff, prod; float ratio; char ch; do{ printf("Enter two integer numbers, A & B: "); fflush(stdin); scanf("%d %d",&A,&B); sum = Add(A,B); diff = Subtract(A,B); prod = Multiply(A,B); ratio = Divide(A,B); InitPairs(pairs); PrintPairs(pairs); fflush(stdout); printf("The sum (A+B) is %d\n", sum); printf("The difference (A-B) is %d\n", diff); printf("The product (A*B) is %d\n", prod); printf("The ratio (A/B) is %5.2f\n", ratio); PrintPairs(pairs); printf("Want to continue?[y/n]: "); fflush(stdin); scanf("%c", &ch); printf("\n"); } while (ch == 'y' || ch == 'Y'); } int Add(int A, int B){ return A + B; } int Subtract(int A, int B){ return A - B; } float Divide(int A, int B){ if( B != 0) return ((float)A)/B; else return -999; } int Multiply(int A, int B){ return A * B; } void InitPairs(IntegerPair pairs[]){ int I; for(I = 1; I <= 20; I++) { pairs[I].x = I; pairs[I].y = 20 - I; } } void PrintPairs(IntegerPair pairs[]){ int I; printf("\n"); for(I = 1; I <= 20; I++) printf("%d %d\n",pairs[I].x,pairs[I].y); printf("\n"); printf("\n"); } Setting Breakpoints To control where your program stops running you will have to set breakpoints. The simplest way to set a breakpoint is with Debug-Toggle-Breakpoint or F5 key. Move the cursor to line 28, scanf("%d %d", &A, &B);, and press F5. Turbo debugger highlights the line, indicating there is a breakpoint set on it. Now select Debug-Run or press Ctrl-F9 to execute your program without interruption. The program stops at line 28. What has happened is, the debugger has executed the intervening statements, from printf("Enter two integer numbers, A & B: "); to scanf("%d %d",&A, &B); . Press F5 again to remove the breakpoint. Running and stopping the program To run the program, choose Debug-Step over or press F8. This allows execution one line at a time, until the first breakpoint, in the program . This brings up a window, titled "TDDEMO1.EXE". The window displays the line Enter two integer numbers, A & B. This window is the program input/output window, through which you interact with the program. The scanf("%d %d",&A,&B) statement is now high-lighted. Pressing F8, brings the program input/output screen to the foreground, with the cursor blinking after the words Enter two integer numbers, A & B. That is because the scanf statement is waiting for you to enter two numbers. Type two integers and press ENTER. This will cause the next line to be highlighted. This process of executing one program statement at a time is called Single stepping. Tracing in procedures and functions When debugging a program, it sometimes becomes necessary to check the inner workings of a function to ensure its correctness. Select Debug-Trace Into or press F7 when the program has stopped at a statement containing the function call. TDW traces into the function, if it is accessible to the debugger and highlights the first statement in the function. Set a breakpoint at the line sum = Add(A, B); In our program, the execution will now stop at this statement when resumed. This statement contains a call to the function Add. Press F7 to trace into function Add. The first statement return A + B; in the function is now highlighted. Press F8 to resume execution. The function now returns control to the calling routine. The statement diff = Subtract(A,B); , following the statement sum = Add(A,B); is now highlighted. Examining program variables The Watches window can be opened by selecting the View-Options and it shows the value of variables you specify. For example, to watch the value of the variable sum, move the cursor to the variable name on line 30. Then choose Debug-Add watch or press Ctrl F5. The variable sum now appears in the Watches window along with its type and value. As you execute the program, Turbo debugger updates this value to reflect the variable's current value. Examining simple C data objects Once you have stopped your program, there are a number of ways of looking at data using the Inspect command. This very powerful facility lets you examine data structures in the same way that you visualize them when you write a program. The Debug-Inspect... command lets you examine any variable you specify. Suppose you want to look at the value of the variable prod Move the cursor below the variable and choose Debug-Inspect... An Inspector window pops up. The first line tells you the variable name and type of data stored in it; the second line shows its value and the address in memory. Examining compound C data objects A compound data object such as an array or structure, contains multiple components. The variable pairs is a compound object. It is an array of records. To examine its content, invoke the Inspector window as described above. The Inspector window shows the values of the 20 elements of pairs. Use the arrow keys to scroll through the 20 elements. The title of the window shows the name of the data you are inspecting. A new Inspector window appears, showing the contents of that element in the array. The Inspector window shows the contents of a record of type integerpair. If one of these were in turn a compound data object, you could issue an Inspect command and dig down further into the data structure. Changing C data values So far, you have learned how to look at data in the program. Here you will learn to change the value of data items. Use the arrow keys to go to line 33 in the source file. Place the cursor at the variable A and choose Debug-Evaluate/Modify. The window now shows the value of variable A. you can enter any C expression that evaluates to a number. Type A+10 and press ENTER. The new value evaluated can be seen in the middle Result pane. Now, in the bottom pane with title New Value, enter a new value and press ENTER. Variable A takes the new value. Reference This section is a reference to using the different commands in TDW. The commands are categorized into two groups namely, "Controlling program execution" and "Examining and modifying data," according to their functionality. Controlling program execution When you debug a program in TDW, you execute portions of it and check at stopping points to see if it is behaving correctly. TDW provides you with a number of ways to control your program's execution. You can • stepping over source code • tracing into code • setting conditional/unconditional breakpoints The Debug menu and the Speedup menu contain all the commands that are needed to control the execution of a program. The Debug menu The Debug menu has a number of options for executing different parts of your program. Since these options are used frequently, most are available on function keys. Following is the description of some of these options. The letters in the brackets stand for function keys with which the command can be invoked. Run [Ctrl-F9] The Run menu Runs your program without stopping. Control returns to TDW when one of the following events occurs: • Your program terminates. • A breakpoint with a break action is encountered. • You interrupt execution with Ctrl-Break. Trace Into [F7] Executes a single source line. If the current line contains a function call, then the debugger traces into the function if it is accessible to the TDW. Step Over [F8] Executes a single source line, skipping over any function calls. TDW treats any function call in a line as part of the line. You do not end up at the start of one of the functions or procedures. Instead, you end up at the next line in the current routine or at the previous routine that called the current one. Toggle BreakPoint [F5] When the cursor is on a source line, then a breakpoint is set at that line when this option is chosen. If it is already a breakpoint then the breakpoint is removed. Find execution point Finds the point in the program where execution is to resume. This can be of use when debugging a large program. Add breakpoint New breakpoints can be added during debugging and this option brings up a window. Options to set a conditional breakpoint under a specific condition are available in this window. Pause program The program can be paused at any point in the debugging process with this option. Terminate program [Ctrl-F2] If you are debugging a program that requires as much memory as possible to complie, then choose this option after the debugging session. Add watch [Ctrl-F5] You could add a new watch variable during the debugging session. The display type of the variable, the radix etc. can be selected. Evaluate/Modify Any expression can be evaluated except those that • contain symbols or macros defined with # define • local or static variables not in the scope of the function being executed • function calls Inspect... As previously explained variables and structures (both simple and complex) can be inspected during debugging. Speedup Menu This is a small menu that comes up when the right mouse button is clicked or when Alt-F10 is pressed. Browse symbol You can choose to browse any variable or structure in your program. If the structure has more than one elements then you could further inspect any of them. View Message window Any messages that may appear during linking and running of the program shows up in this window. Globals This window shows all the global variables and functions that have been defined in the program. Watch This window shows all the variables and structures that are being watched in the debugging session. The values of the variables during the different stages of execution are shown. Call Stack This window shows the contents of this program stack. The different function calls in the program can be seen as being the stack contents when the TDDEMO1.C program is exected. Register This window displays the contents of the data, pointer, index, segment, and instruction pointer registers, as well as the settings of the status word or flags. Event log This window displays the results of breakpoints, Windows messages, and output messages generated while using the debugger. read less
Comments

Tutor

Press F7 and checj
Comments

Online Computer Trainer

Goto Debug Menu -> Watches -> Add watch and add the variables to trace. Press F7 to trace the program line-by-line. A watch can be added using CTRL + F7 also. To remove watches, goto debug menu -> watches -> remove all watches.
Comments

Tutor

F7,F8
Comments

BE Computer

IN Turbo C Use f7 and f8 to trace the program
Comments

View 4 more Answers

Related Questions

Which should I learn first, C or UNIX?
As you know C is a programming language and UNIX is Operating System if you want to grow your career as Programmer/Developer than go for C/C++ programming as it is very basic programming languages and...
Tushar
0 0
6
Why should I learn Python over C or C++?
There are definite differences. C++ is a strongly typed language and Python is not. There's no need to declare variables. ... (I generally don't like languages to be dependent on any kind of formatting,...
Sajini
What is the difference between n=1 and n==1 in the C language?
'=' is ASSIGNMENT operator , where as '==' is COMPARISON operator. int a=7; assigns the variable a an integer value 7 , where as a==7; checks if the VALUE of a is EQUAL to 7.
Soujanya
0 0
8
Can we pass arguments in the main function in C language?
Yes. it is possible to pass arguments into the main function.
Mukesh
0 0
7
Are C Programmers currently in demand?
Ofcourse, C is alwasy in demand. In the beginning a lot of the big project developed in C language. Now a days, there are a lot of language in market and speciallity is growing in IT field. For a big organization...
Harsha

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

Recursion in C Programming
The process of calling a function by itself is called recursion and the function which calls itself is called recursive function. Syntax of Recursive Function returntype recursive_func () { statements; ...
R

Ravindra Yadav

2 0
0

C Language
To get help in C window (for keywords, functions) press Alt +F1.To delete a single line , use the shortcut key CTRL +Y.If you got error about the path when you execute a C pgm, check the Options menu =>Directories.
T

Thilagam S.

0 0
0

Compiler vs Interpreter
Compiler Interpreter Convert all the code into binary format and execute. Convert one statement at a time and execute, then Convert next statement and execute. After conversion, source...

Understanding Computer Science Concepts with Images and Videos..
All Computer science concepts relating to programming and software development are only virtual. It cannot be practically shown as a hardware parts of a computer. But for better understanding it should...

Creating First Program Using C Language
Step 1: Install and setup Turbo C compiler on your computer. Step 2: Open Turbo C from your Desktop or Programs menu. Select “File” from menu bar and select option “New”. Step...

Recommended Articles

Lasya Infotech is a Hyderabad based IT training institute founded in 2016 by O Venkat. Believing in his innovation, passion and persistence and with a diverse blend of experience, he started his brainchild to deliver exemplary professional courses to aspiring candidates by honing their skills. Ever since the institute envisions...

Read full article >

Brilliant Academy is one of the reputed institutes for B.Tech tuition classes. This institute is specialised in delivering quality tuition classes for B.E, Engineering - all streams and Engineering diploma courses. Incorporated in 2012, Brillant Academy is a brainchild of Mr Jagadeesh. The main motto of the academy is to...

Read full article >

Applications engineering is a hot trend in the current IT market.  An applications engineer is responsible for designing and application of technology products relating to various aspects of computing. To accomplish this, he/she has to work collaboratively with the company’s manufacturing, marketing, sales, and customer...

Read full article >

Software Development has been one of the most popular career trends since years. The reason behind this is the fact that software are being used almost everywhere today.  In all of our lives, from the morning’s alarm clock to the coffee maker, car, mobile phone, computer, ATM and in almost everything we use in our daily...

Read full article >

Looking for C Language Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for C Language Classes?

The best tutors for C Language Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn C Language with the Best Tutors

The best Tutors for C Language Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more