Hey everyone, I am currently working through the K&R book trying to teach myself C and one of the exercises is confusing me. The exercise is this:
Write a program detab that replaces tabs in the input with the proper number of blanks to space to the next tab stop. Assume a fixed set of tab stops, say every n columns. Should n be a variable or a symbolic parameter?
I think I understand what it is asking and have written a program that seems to work. I wrote the program to display the modified tabs rather than changing the string entered itself though I don't think it would be too difficult to switch in any case. Here is the function I wrote:
Does anyone have any suggestions on how that could be improved or changed? Or maybe I am missing the point of the exercise entirely . I am very new to C so any suggestions would be greatly appreciated.
void printstring(char string, int n)
int i, x;
for(i=0; string[i]!='\0'; i++, currentcolumn++)
for(x=0; currentcolumn%n!=0; x++)
if(currentcolumn==80 || string[i]=='\n')