All pastes #158033 Raw Edit

Someone

public text v1 · immutable
·published 2006-09-01 22:29 UTC
rendered paste body
/* detab.c
 *
 * Program to detabalize input :- )
*/

#include <stdio.h>

void detab(char s[], int size);

#define COL 4
#define SIZE 100

int main() {
        int c, i;
        char s[SIZE];
        int size = SIZE;

        i = 0;
        while( (c = getchar()) && c != '\n' ) {
           s[i] = c;
           i++;
        }

        if (c == '\n') {
           s[i]   = '\n';
           s[i+1] = '\0';
        }

        detab(s, size);

        return 0;
}

void detab(char s[], int size) {
        int i, y, z;
        char o[SIZE];

        for (i=0, y=0; i < size && s[i] != '\n'; i++) {
                if (s[i] == '\t') {
                        for(z=0;z<COL;++z) {
                                o[y] = ' ';
                                ++y;
                        }
                } else {
                        o[y] = s[i];
                        ++y;
                }
        }

        o[y]   = '\n';
        o[y+1] = '\0';

        printf("%s\n",o);
}