If your question is: “What is it asking me to do?” I think I can help by paraphrasing the original question (asking the same question in a different way).
Write a program that takes spaces as input and produces as output the visually equivalent text using tabs as much as possible.
For example, with tabstops every 8 characters and showing spaces as '.' and tabs like '-';
input; ".foo:...bar;......#comment" output; ".foo:-bar;-..#comment" input; ".......-foo:.....bar;......#comment" output; "-foo:-.bar;-...#comment"
Write the program so that the tabstop n parameter can change, i.e. allow n values other than 8. Be prepared to justify your decision to make n a constant or, alternatively, a variable.
Edit I looked at your code, and I think it is more complicated than necessary. My advice is to make this a character at a time. There is no need to buffer an entire line. Count the columns when reading each character ('\ n' resets it to zero, '\ t' hits it by 1 or more, other characters increase it). When you see a space (or tab), don't emit anything right away, start the entabbing process, emit zero or more tabs, and then spaces later (in "\ n" or a character without spaces, whichever comes first).
The final hint is that a state machine can make such an algorithm much easier to write, validate, validate, and read.
Edit 2 In a shameless attempt to get the OP to accept my answer, I now went ahead and actually coded the solution myself, based on the hints I suggested above and my comments in the discussion.
// K&R Exercise 1-21, entab program, for Stackoverflow.com #include <stdio.h> #define N 4 // Tabstop value. Todo, make this a variable, allow // user to modify it using command line int main() { int col=0, base_col=0, entab=0; // Loop replacing spaces with tabs to the maximum extent int c=getchar(); while( c != EOF ) { // Normal state if( !entab ) { // If whitespace goto entab state if( c==' ' || c=='\t' ) { entab = 1; base_col = col; } // Else emit character else putchar(c); } // Entab state else { // Trim trailing whitespace if( c == '\n' ) { entab = 0; putchar( '\n' ); } // If not whitespace, exit entab state else if( c!=' ' && c!='\t' ) { entab = 0; // Emit tabs to get close to current column position // eg base_col=1, N=4, col=10 // base_col + 3 = 4 (1st time thru loop) // base_col + 4 = 8 (2nd time thru loop) while( (base_col + (N-base_col%N)) <= col ) { base_col += (N-base_col%N); putchar( '\t' ); } // Emit spaces to close onto current column position // eg base_col=1, N=4, col=10 // base_col -> 8, and two tabs emitted above // base_col + 1 = 9 (1st time thru this loop) // base_col + 1 = 10 (2nd time thru this loop) while( (base_col + 1) <= col ) { base_col++; putchar( ' ' ); } // Emit buffered character after tabs and spaces putchar( c ); } } // Update current column position for either state if( c == '\t' ) col += (N - col%N); // eg col=1, N=4, col+=3 else if( c == '\n' ) col=0; else col++; // End loop c = getchar(); } return 0; }