Im trying to help out a friend in a beginning C class. The problem is stumping myself and another somewhat C literate friend of mine(we both have taken some advanced C courses). Heres the problem.
You have to make two cities, one tampa, one orlando in boxes on the screen. You then have to make a car(arrow) travel from left to right btw the cities, turn around (arrow change?), then return to the beginning city.
I cannot figure this out, I have trid doing a couple different array setups, but i CANNOT seem to grasp how to get the arrow to move from left to right, right to left in between the two cities.(cannot just use tab, he specifically stated she needed to use arrays). Now, the only help i have thus far been able to find is this (program below): but its not helping me out that much since its moving the rocket upwards instead of left to right, right to left.
IF anyone has any ideas on how to go about doing this I am open for suggestions
Thanks
#include <stdio.h> // for printf()
#include <conio.h> // for getche()
#define ROWS 10 // dimensions of image
#define COLS 5 // to be rotated
#define HEIGHT 25 // height of screen in rows
void main(void)
{
int count, j, k;
char *ptr[ROWS]; // pointers to rows
char *temp; // pointer storage
char pict[ROWS][COLS] = // rocketship
{ { 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 },
{ 0, 0, '\x1E', 0, 0 },
{ 0, '\x1E', '\xDB', '\x1E', 0 } };
char gnd[] = // ground line
{ '\xCD', '\xCD', '\xCD', '\xCD', '\xCD', 0 };
for(count=0; count<ROWS; count++) // set up pointers
*(ptr+count) = *(pict+count);
for(count=0; count<ROWS-1; count++)
{
for(j=0; j<HEIGHT; j++) // print blank lines
printf("%c", '\n');
for(j=0; j<ROWS; j++) // print rocket
{
for(k=0; k<COLS; k++)
printf("%c", *(*(ptr+j)+k) );
printf("%c", '\n' );
}
printf("%s\n", gnd); // print ground
temp = *ptr; // save top row
for(j=0; j<ROWS-1; j++) // rotate pointers
*(ptr+j) = *(ptr+j+1); // upward
*(ptr+ROWS-1) = temp; // top row to bottom
getch(); // wait for keypress
} // end for(count)
} // end move
You have to make two cities, one tampa, one orlando in boxes on the screen. You then have to make a car(arrow) travel from left to right btw the cities, turn around (arrow change?), then return to the beginning city.
I cannot figure this out, I have trid doing a couple different array setups, but i CANNOT seem to grasp how to get the arrow to move from left to right, right to left in between the two cities.(cannot just use tab, he specifically stated she needed to use arrays). Now, the only help i have thus far been able to find is this (program below): but its not helping me out that much since its moving the rocket upwards instead of left to right, right to left.
IF anyone has any ideas on how to go about doing this I am open for suggestions
#include <stdio.h> // for printf()
#include <conio.h> // for getche()
#define ROWS 10 // dimensions of image
#define COLS 5 // to be rotated
#define HEIGHT 25 // height of screen in rows
void main(void)
{
int count, j, k;
char *ptr[ROWS]; // pointers to rows
char *temp; // pointer storage
char pict[ROWS][COLS] = // rocketship
{ { 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 },
{ 0, 0, '\x1E', 0, 0 },
{ 0, '\x1E', '\xDB', '\x1E', 0 } };
char gnd[] = // ground line
{ '\xCD', '\xCD', '\xCD', '\xCD', '\xCD', 0 };
for(count=0; count<ROWS; count++) // set up pointers
*(ptr+count) = *(pict+count);
for(count=0; count<ROWS-1; count++)
{
for(j=0; j<HEIGHT; j++) // print blank lines
printf("%c", '\n');
for(j=0; j<ROWS; j++) // print rocket
{
for(k=0; k<COLS; k++)
printf("%c", *(*(ptr+j)+k) );
printf("%c", '\n' );
}
printf("%s\n", gnd); // print ground
temp = *ptr; // save top row
for(j=0; j<ROWS-1; j++) // rotate pointers
*(ptr+j) = *(ptr+j+1); // upward
*(ptr+ROWS-1) = temp; // top row to bottom
getch(); // wait for keypress
} // end for(count)
} // end move
