That's detab from K&R Chapter 1.
This is what I came up with:
Code:
#include <stdio.h>
#define TABS 4
#define MAXLINE 100
int main(int argc, const char * argv[])
{
char newline[MAXLINE], c;
int i;
int cnt = 0;
printf("Give me a line sucker!\n");
while ((c = getchar()) != '\n') {
if (c == '\t') {
do{
newline[cnt] = ' ';
++cnt;
}while (cnt % TABS); //find the Tab spot by modulus. Clean
//division (no remainder) defines a Tab spot.
}
else {
newline[cnt] = c;
++cnt;
}
}
for (i = 0; i < cnt; i++) {
printf("%c",newline[i]);
}
printf("\n");
return 0;
}