I wrote a program to convert spaces to tabs. If there are 4 spaces it should convert them to tab. Please let me know how to improve it.
#include <stdio.h>
#define TABVALUE 4
int c, d, s;
int main(void) {
c = s = d = 0;
while ((c = getchar()) != EOF) {
if (c == ' ') {
s++;
for (int j = 0; j < TABVALUE - 1; j++) {
d = getchar();
if (d == ' ') {
s++;
}
}
if (s == TABVALUE) {
putchar('\t');
s = 0;
}
} else {
putchar(c);
}
}
return 0;
}