Code:
void display( int offset, int width )
{
/* ?= N ===== N =? */
int x = 0;
/* prepadding */
for( x = offsest % 5; x > 0; x-- )
putchar( '=' );
printf( "%d", 10 * offset++ );
for( x = 0; x < 5; x++ )
putchar( '=' );
printf( "%d", 10 * offset++ );
/* postpadding */
for( x = (offsest + width) % 5; x > 0; x-- )
putchar( '=' );
}
I think that's the general idea of what you're trying to do. Now naturally you'd want to use some looping in the center if you had a different amount of repeating to do there of your complete segments.
Originally Posted by
Babkockdood
Post some source code maybe? Maybe tell us the big picture you're trying to accomplish?
He's basically trying to display a floating window of text. Consider a string that is the alphabet: "abcdefghij...z". You want to display 5 characters at a time, at any given spot on that string.
Code:
printf("%5s", alphabet + (offset > 21 ? 22 : offset < 0 ? 0 : offset) );
That should give you a five character chunk of your alphabet string, based on whatever offeset you want to start on, without running off each end.
Quzah.