1 / 4

Testing a program

This guide explains how to test and debug a program by removing syntax and link errors, checking for runtime, semantic, and logic errors, and reading input from the terminal using the scanf() function.

johncarson
Download Presentation

Testing a program

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Testing a program • Remove syntax and link errors: Look at compiler comments where errors occurred and check program around these lines • Run time errors: • Semantic errors (check function arguments) • Logic errors • manual trace • add debugging code to check variables use print statements • check expressions; order of precedence, operation rules

  2. Reading input from terminalscanf() • read data typed at the keyboard • convert the data to its internal form • store it into an object How can this be done? • scanf() is a function • Functions cannot directly access a variable by its name defined in another function • If scanf() cannot directly access a variable in main(), it cannot assign a value to that variable

  3. Address of variable Use address of variable to access object int x; scanf(“%d”,&x); Scanf command uses a format string similar to printf command. %d indicates variable is an integer. Scanf reads input, converts it to an internal form, and stores it into an integer object whose address is given by the next unmatched argument. Value read is stored into the object whose address is &x and the value is stored into x.

  4. Additional scanf() comments • scanf() is buffered as the input data is not read until a full buffer has been entered, indicated by a return key (a newline). • scanf() is free form as it ignores blanks. The first data item found in the input will be converted and stored in the address provided. Likewise, scanf() will not return until it has converted the requested number of data items. • Additional data in the buffer is not affected by scanf()

More Related