Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I went through and basically sorted out all the warts, and explained why. A lot of it amounts to the fact that <em>if your compiler spits out warnings, you have to listen to them</em>.</p> <pre><code>/* Changed: Code formatted for my sanity */ #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;unistd.h&gt; #include &lt;fcntl.h&gt; #include &lt;errno.h&gt; #include &lt;string.h&gt; /*global definitions*/ #define WIDTH 480 #define HEIGHT 240 /*global declarations*/ int w,h,scrn, bytewrite; /* Changed: to a short because I don't like the fact that I might be overwriting memory on accident (in colorq). */ unsigned short red, green, blue; static unsigned long rgb[WIDTH][HEIGHT]; /* Changed: Some format strings have been changed to get rid of compiler warnings. */ /*function declarations*/ void colorq(); /* Changed: Specify the second dimension when you're passing an array. */ void rgb_rectdraw(int x, int y, int w, int h, unsigned char red, unsigned char green, unsigned char blue, unsigned long rgb[][HEIGHT]); /* Changed: always pass an array of arrays. */ void rgb2yuv(unsigned long rgb[][HEIGHT]); /* Function Name: main Purpose: main function */ int main(int argc, char** argv) { printf("\n"); int x, y; /*call colorq to create a 32bit number of RGB*/ colorq(); /* call rgb_rectdraw to draw a rectangle RGB array */ rgb_rectdraw(x, y, w, h, red, green, blue, rgb); /* call rgb2yuv to take the RGB array and covert it to a YUV array */ rgb2yuv(rgb); return 0; } /* Function name: color q Purpose: asks user to input colors from 0 to 255 in RGB format */ void colorq(){ /* Suggestion: restructure this method to just take in all its input locally, then return a rgbpixel. */ printf("Please enter a color for Red Green and Blue from 0 to 255:\n"); scanf("%hu", &amp;red); scanf("%hu", &amp;green); scanf("%hu", &amp;blue); printf("\n"); return; } /* Function name: rectdraw Purpose: Draws a rectangle array */ void rgb_rectdraw(int x, int y, int w, int h,unsigned char red, unsigned char green, unsigned char blue, unsigned long rgb[][HEIGHT]) { unsigned long rgbpixel; /* testing only take out when finished debugging why red is always 0 after scanf */ red = 255; printf("red set to 255 for debugging\n"); /*creates a 32-bit number of RGB*/ /* Changed: Added the extra 0xFF masking because of shortness rather than charness. */ rgbpixel = ((red &amp; 0xFF) &lt;&lt; 16) | ((green &amp; 0xFF) &lt;&lt; 8) | (blue &amp; 0xFF); printf("%#lx\n",rgbpixel); /*create array of width w height h*/ /*initialize array*/ /* Changed: fill the size of one element times the number of elements */ memset(rgb, 0, sizeof(unsigned long) * HEIGHT * WIDTH); int i, j, startx, stopx, starty, stopy; printf("enter width and height of rectangle in pixels\n"); scanf("%d %d", &amp;w, &amp;h); printf("enter offset x pixels and y pixels of rectangle:\n"); scanf("%d %d", &amp;x, &amp;y); startx=x; starty=y; stopx=x+w; stopy=y+w; /* creates array of w and h of int rgh */ for(i=startx; i &lt;= stopx; i++){ for(j=starty; j &lt;= stopy; j++){ rgb[i][j] = rgbpixel; } j = 0; } printf("original rgb %#lx\n", (long unsigned int) rgb); return ; } /* *Function Name: rgb2yuv *Purpose: convert the RGB array to a YUV array */ void rgb2yuv(unsigned long rgb[][HEIGHT]){ int i,j; /* Changed: You can't just dereference rgb twice -- you have to use array notation here. */ printf("ptrpassed = %#lx\n", rgb[0][0]); for(i=0; i&lt;=WIDTH; i++){ for(j=0; j&lt;=HEIGHT; j++){ } } printf("\n"); return; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload