I'm a newb at programming, especially at C; just trying to scratch an itch.
Trying to use ncurses to do an ASCII-art man doing jumping jacks, trying for the past three days, but I'm just not getting "Strings" in C (I understand that strings aren't really a C concept, just arrays of chars), and I'm not really getting pointers, and I'm not really getting pointers to char arrays, etc.
Forgive the art; it's just a proof of concept.
And I'm not trying to do the animation (or even use ncurses) at this point (that part's easy); I'm just trying to figure out how to use arrays to store my animation frames (though I'm open to other ideas of doing it, if they are conceptually simpler).
#define NumOfFrames 4 // Num of animation frames
#define WidthOfFrames 15 // Characters per animation line
#define FrameHeight 5 // Frame is this many lines tall.
const char *D51[NumOfFrames][FrameHight][WidthOfFrames] = {{
" \\ 0 / ",
" \\|/ ",
" | ",
" / \\ ",
"_/ \\_ "
},
{
" ",
" __0__ ",
"/ | \\ ",
" / \\ ",
" _\\ /_ "
},
{
" ",
" o ",
" /\\ /\\ ",
" |/ \\| ",
" _\\ /_ "
},
{
" ",
" ",
" __ ",
" /_\\\\0_ ",
" _\\\\/_ \\_"
}};
void main(int argc, char *argv[]) {
FILE *f = fopen("log.txt","w");
if (f == NULL) {
printf("Error opening file!\n");
exit(1);
}
// Try to print each frame to a text file to wrap
// my brain around how this works.
for (int x=0;x<NumOfFrames;x++) {
for (int y=0;y<FrameHeight;y++) {
for (int z=0;z<WidthOfFrames;z++) {
fprintf(f, "%c", D51[x][y][z]);
}
fprintf(f,"\n");
}
}
fclose(f);
}
In this code I'm just trying to figure out how to manipulate the strings, writing the images to a text file. Once I understand the concepts, I'll convert it to ncurses "graphical" format; that part is easy, and is not reflected in this sample code.
My problem is that no matter what permutations I try in my experiments -- a * here and not there, or there and here, or there but not here, or two indexes instead of three, or this or that -- I can't figure out what's going on under the hood. I can find examples on the web of what I need if I'm using integers, but using chars/strings/pointers adds a whole 'nuther level of complexity that I'm just not getting. Any help in better understanding the concepts I need would be much appreciated.