This C program is supposed to ask the user for the number of rows and columns, and output a rectangle of asterisks, like a visual times table. Not even getting to the output part yet, structs confuse the hell out of me, and when i try to compile, gcc gives these errors:
multiply.c:18: error: expected expression before box
multiply.c: In function draw_box:
multiply.c:51: error: incompatible type for argument 1 of draw_line
multiply.c:11: note: expected box but argument is of type int
really, using struct variables with functions is what's throwing me off
Code:#include <stdio.h> typedef struct { int rows; int columns; } box; int input_rows(); int input_columns(); void draw_box(); void draw_line(box data); int main() { box data; data.rows = input_rows(); data.columns = input_columns(); draw_box(box data); return 0; } int input_rows(){ box data; do{ printf ("Number of rows? \n"); scanf ("%d", &data.rows); } while (data.rows <= 0); return (data.rows); } int input_columns(){ box data; do{ printf ("Number of columns? \n"); scanf ("%d", &data.columns); } while (data.columns <= 0); return (data.columns); } void draw_box(){ box data; int x; for(x=1;x<=data.rows;x++) { draw_line(data.columns); } } void draw_line(box data){ int y; for(y=1;y<=data.columns;y++); { printf("*"); } }