I17 Answer


#include <stdlib.h>
#include <stdio.h>
#include "basicImage.c"

int main ( int argc, char* argv[] )
{
  image img ;
  int r, c;
  int nrows, ncols, below, above;

  if ( argc != 6)
  {
    printf("diagImage fileName nrows ncols below above\n");
    system( "pause" );
    return EXIT_SUCCESS;
  }

  nrows = atoi( argv[2] );  /* might want to do some error checking here */
  ncols = atoi( argv[3] );
  below = atoi( argv[4] );
  above = atoi( argv[5] );

  if ( newImage( &img, nrows, ncols ) == NULL )
  {
    printf(">>error<< can't allocate memory\n");
    return;
  }

  for ( r = 0; r<img.nrows; r++ )
    for ( c = 0; c<img.ncols; c++ )
      if ( ncols*r>nrows*c )
        setPixel( img, r, c, below );
      else
        setPixel( img, r, c, above );

  writePGMimage( img, argv[1]);
  freeImage( &img );
  
}


back