I am really stuck here so just looking for some hints and advice. I dont know how to explain what my assignment is without actually posting what I have. So far I am only through the first bullet. I dont know where to go from there. I have read through the entire chapter again and I just dont know what parameters to pass to function drawImage and how to write the other two required functions. So, this is everything I have, I am not asking anyone to do this assignment for me, I simply want some pointers, no pun intended:
The Assignment
The objective of this program is to create an image (25 x 25) with a square of a user-defined size centered on the image.
The program will:
• Ask the user what size of square to draw (Maximum size of a side is 23, make sure to error check this entry)
• Call the function drawImage, included in the drawImage.h header file
• Call a function to print the image to the screen, using an * to demarcate the square
• Call a function that uses a pair of pointers to search through the image to determine where the edge of the square is located. This function should generate a new image that has only the outline of the square.
• Lastly recall the print function to print the image with the outline.
Submit the code as hw7-2.c
Hints:
1. Use these function prototypes
void printImage(int image[]);
void edgeDetection(int image[], int edge[]);
2. If using a one-dimension array to define a two-dimension image the following is a useful method for incrementing through the array: r + c*SIZE. Where r is the current row, c the current column and SIZE is the length of a row.
Given header file
This all I have so far, dont know what to do next, I do know pointers are necessary:Code:/******************************************************************
* *
* Programmer: *
* Name: drawImage *
* Function: Draws a square onto the center of a canvas *
* Input: 1-D Array, width of array, length of square, *
* whether the square side is even or odd length *
* line and give a description of what it is> *
* Output: An array with 1s where the square is on the image *
* *
******************************************************************/
//Function to draw a square centered within an image
void drawImage( int image[], int size, int side, int even)
{
int r, c;
//loop through the image setting the appropriate pixels to "white" if the square is present
for (r = 0; r < size; r++)
{
for (c = 0; c < size; c++)
{
if ((size/2 - side/2) > r || (size/2 + side/2 - even) < r )
{
//Leaves the value of the array as it is since no part of the image appears in this row
}
else if( (size/2 - side/2) > c || (size/2 + side/2 - even) < c )
{
//Leaves the value of the array as it is since no part of the image appears in these columns
}
else
{
image[r+c*size] = 1;
}
}
}
}
Code:#include <stdio.h>
#include "drawImage.h"
/*function prototypes*/
void printImage(int image[]);
void edgeDetection(int image[], int edge[]);
/*function main begins program execution*/
int main (){
int SIZE;
printf("Please enter the size of the square you would like to draw"
"\n(maximum size is 23):"); /*print statement*/
scanf("%d",&SIZE);
if(SIZE>23){
printf("The size of the square cannot be larger than 23, please start again\n");
return 0;
} /*end if*/
return 0; /*indicate program ended successfully*/
} /*end function main*/