Sample Program
On-Line Demonstrations of FlexeLint and PC-lint (aka FlexeLint for Windows)
Bug of the Month for March 2006
Bug of the Month Samples
In computing the average wind velocity for a cold windy March day, the result, instead of being above 10 was below 1. What's the problem?
Modify this example, if desired, and then hit the Analyse Code button
#include
const char *wind[4] = { "N 12 MPH", "NW 14 MPH", "N 22 MPH", NULL }; float average( const char *a[] ) { float sum=0, vel=0; int i; char direction[10]; for( i = 0; a[i]; i++ ) { sscanf( a[i], "%s %d", direction, &vel ); sum += vel; } return sum / i; } int main() { printf( "Average wind velocity is %g.\n", average(wind) ); return 0; }
Run FlexeLint on Bug of the Month Samples
Home
|
Examples
|
Contact
|
Order
PC-lint and FlexeLint are trademarks of Gimpel Software
Copyright © 2009, Gimpel Software