#include<stdio.h> #define TABINC 8 main() { int c,nb,nt,pos; nb=nt=0; for(pos=1;(c=getchar())!=EOF;++pos){ if(c==‘ ‘){ if(pos%TABINC != 0) ++nb; else{ nb=0; ++nt; } }else{ for( ;nt>0;--nt) putchar(‘\t‘); if(c==‘\t‘) nb=0; else for( ;nb>0;--nb) putchar(‘*‘);// 将空格换成*,便于观察 putchar(c); if(c==‘\n‘) pos=0; else if(c==‘\t‘) pos=pos+(TABINC-(pos-1)%TABINC)-1; } } }
if(c==‘\n‘ || c==‘\t‘) pos=0;
原文:http://my.oschina.net/sukai/blog/310504