From my C university book 'The C Programming Language' by Brain W.Kernighan and Dennis M.Ritchie. Excercise 1 - 20.
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?
#include <stdio.h>
#define TABSTOP 8
#define MAXLINE 1000
int getline(char s[], int len);
int main()
{
char line[MAXLINE];
while ((getline(line, MAXLINE) > 0))
{
int i, j, count;
count = 0;
for (i = 0; line[i] != '\0'; ++i)
{
if (line[i] == '\t')
{
for (j = 0; j < TABSTOP - count; ++j)
{
putchar(' ');
}
count = 0;
}
else
{
++count;
if (count >= TABSTOP)
count = 0;
putchar(line[i]);
}
}
}
system("pause");
return 0;
}
int getline(char line[], int len)
{
int c, i;
for (i = 0; i < len - 1 && (c = getchar()) != EOF && c != '\n'; ++i)
line[i] = c;
if (c == '\n')
{
line[i] = c;
++i;
}
line[i] = '\0';
return i;
}
My concerns are that I didn't get the question right, did they mean that every time I see a tab in the input I need to put the corresponding amount of spaces instead of tabs?
Are there any flaws or bugs in the code?
I didn't understood what is a 'symbolic parameter', did they mean symbolic constant?
By 'n' did they mean what I did with the 'TABSTOP' symbolic constant?