Here you go:
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define DEFAULT_NSPACES 4
int main(int argc, char **argv)
{
int nspaces = DEFAULT_NSPACES;
char buf[BUFSIZ], *p, *q;
int i;
if(argc > 2)
{
fputs("Usage: tabstospaces [<spaces per tab>]\n", stderr);
exit(EXIT_FAILURE);
}
if(argc == 2)
{
nspaces = strtol(argv[1], &p, 0);
if(nspaces < 0 || *p || !*argv[1])
{
fprintf(stderr,
"Specified number of spaces is invalid: %s\n", argv[1]);
exit(EXIT_FAILURE);
}
}
while(fgets(buf, sizeof(buf), stdin))
{
p = buf;
while((q = strchr(p, '\t')))
{
while(p < q)
{
fputc(*p, stdout);
p++;
}
for(i = 0;i < nspaces;++i)
fputc(' ', stdout);
p++;
}
fputs(p, stdout);
}
return EXIT_SUCCESS;
}
Just use it like: tabstospaces [spaces per tab] < input_file > output_file
The spaces per tab is optional.