/*
This program replaces the Tab character by an input number of spaces.
Date: 110510, Tue 10 May 2011 11:29:02 AM IST
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int ch, tab=\'\\t\';
char replace[32+1]; /* who would require 32+ width Tab !! */
strcpy(replace," ");
if (argc==2) {
int c=atoi(argv[1]), i;
if (c<=0 || c>32) {
puts("argument should be a number >0 and <=32");
exit(0);
}
for (i=0; i<c; ++i)
replace[i]=\' \';
replace[i]=\'\\0\';
}
else if (argc>=3) {
puts("usage: replaceTab <#_of_spaces>");
exit(0);
}
while ((ch=getchar())!=EOF)
if (ch==tab)
printf(replace);
else
putchar(ch);
return 0;
}