I've been trying to make a program that animates from an array in C, and I can't get it to work. The idea is to have a separate header file that stores all of the frames of the animation. (all of the frames are just text - ascii) Then in the main program, there is a function called playForward that plays the animation forward.
Here's the main file...
CODE
#include <stdio.h>
#include "frames.h"
void playForward( char *frames );
int main( void ) {
playForward( *bounce );
getchar();
return 0;
}
void playForward( char *frames ) {
int i = 0; /* outer counter */
int j = 0; /* inner counter */
int k = 0; /* double inner counter */
for( i = 0; i < frameNum * frameHeight; i++ ) {
printf( "%s\n", &frames[ i ] );
}
/*for( i = 1; i <= frameNum; i++ ) {
for( j = 0; j < frameHeight; j++ ) {
//for( k = 1; k <= frameLength; k++ ) {
printf( "%s\n", &frames[ j ] );
//}
//printf( "\n" );
}
printf( "\n" );
}*/
}
#include "frames.h"
void playForward( char *frames );
int main( void ) {
playForward( *bounce );
getchar();
return 0;
}
void playForward( char *frames ) {
int i = 0; /* outer counter */
int j = 0; /* inner counter */
int k = 0; /* double inner counter */
for( i = 0; i < frameNum * frameHeight; i++ ) {
printf( "%s\n", &frames[ i ] );
}
/*for( i = 1; i <= frameNum; i++ ) {
for( j = 0; j < frameHeight; j++ ) {
//for( k = 1; k <= frameLength; k++ ) {
printf( "%s\n", &frames[ j ] );
//}
//printf( "\n" );
}
printf( "\n" );
}*/
}
...and here's the header file (frames.h)...
CODE
int frameNum = 5;
int frameHeight = 3;
int frameLength = 5;
char *bounce[] = {
"*****",
"* ",
"*****",
"*****",
" * ",
"*****",
"*****",
" * ",
"*****",
"*****",
" * ",
"*****",
"*****",
" *",
"*****",
};
int frameHeight = 3;
int frameLength = 5;
char *bounce[] = {
"*****",
"* ",
"*****",
"*****",
" * ",
"*****",
"*****",
" * ",
"*****",
"*****",
" * ",
"*****",
"*****",
" *",
"*****",
};
As you can see, the animation is very simple, and I just want to figure out how to make it work.
This is the output I get when I run the program:
CODE
*****
****
***
**
*
*
*
*
****
***
**
*
*
*
*
But I want it to print this:
CODE
*****
*
*****
*****
*
*****
*****
*
*****
*****
*
*****
*****
*
*****
*
*****
*****
*
*****
*****
*
*****
*****
*
*****
*****
*
*****
(or something like that - this forum messes up the spacing in the code
Does anyone know what the problem could be?
Thanks!
*bump*