Explore BrainMass
Share

Using the Print or printf Statement to Debug an Application

This content was STOLEN from BrainMass.com - View the original, and get the already-completed solution here!

How would you use the print statement to debug an application? (Please provide a simple example).

© BrainMass Inc. brainmass.com October 24, 2018, 6:46 pm ad1c9bdddf
https://brainmass.com/computer-science/debugging/using-print-printf-statement-debug-application-48520

Solution Preview

A printf() statement can help you look deep into the action of a program. Although it is used to spot errors and faults but remember it is a non-interactive way of finding what is sometimes equivalent of a "needle in a haystack". I list some of the places you can insert a printf() for possible error checking:
1) Immediately after a scanf() to confirm the data you are reading conforms to the type and variable you as expected.

int main(){
int value;

printf("Please enter a value between 0 and 100");
scanf("%d", value);

/*inserting a printf() statement here ...

Solution Summary

A printf() statement can help you look deep into the action of a program. Although it is used to spot errors and faults but remember it is a non-interactive way of finding what is sometimes equivalent of a "needle in a haystack". In this solution you will learn three practical ways to debug an application illustrated with examples.

$2.19
See Also This Related BrainMass Solution

How to control variations in program

Since every program that is created is different from every other program, what are the variations that we look for and how do we control them?

View Full Posting Details