Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

programming color array problem

Status
Not open for further replies.

RussOSU

Technical User
Apr 16, 2001
93
US
I am trying to learn C and am trying to write a program from a c programming class which involves using symbols and colors to draw a picture with loops, _gotoxy, _textcolor, etc... I am supposed to define a prototype horzLine() and then basically print a horizontal line of *. I am running into a problem with how to actually accomplish my task once I have defined the function. I know I need a loop and the gotoxy and printf. However I am not sure how to go about this so that by using the line
horzLine(x,y,length,symbol,color); I get what I want.

The output should look like

**********


The code for what I have done so far is below

#include <stdio.h>
#include <math.h>
#include <conio.h>

#define BLACK 0
#define DARKBLUE 1
#define DARKGREEN 2
#define DARKCYAN 3
#define DARKRED 4
#define DARKMAGENTA 5
#define DARKYELLOW 6
#define DARKWHITE 7
#define GREY 8
#define BLUE 9
#define GREEN 10
#define CYAN 11
#define RED 12
#define MAGENTA 13
#define YELLOW 14
#define WHITE 15

void horzLine(int x, int y, int length, char symbol, int color);

int main(void) {
int i;
int x;
int y;
int length;
char symbol;
int color;

x=5;
y=4;
length=10;
symbol='*';
color=RED;

**not sure how to start the loop**
horzLine(x, y, length, symbol, color);
**what do I need here with my printf**
fflush (stdout);

return 0;
}



 
The loop goes inside the function
Code:
void horzLine(int x, int y, int length, char symbol, int color) {
  int i;
  for ( i = 0 ; i < length ; i++ ) {
    cprintf(&quot;%c&quot;,symbol);
  }
}
Now you can add the gotoxy() and setcolor()

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top