Skip to content

Instantly share code, notes, and snippets.

@tomcha
Created March 17, 2015 10:50
Show Gist options
  • Select an option

  • Save tomcha/1c4cb0d63c4f85d71241 to your computer and use it in GitHub Desktop.

Select an option

Save tomcha/1c4cb0d63c4f85d71241 to your computer and use it in GitHub Desktop.
1-20
#include <stdio.h>
#define MAXCHAR 100
#define TABSTOP 5
int detab(char strings[], int clocate, int n);
void cleararray(char array[]);
int main(){
char strings[MAXCHAR];
int c;
int clocate;
clocate = 0;
while((c = getchar()) != EOF){
if(c == '\t'){
clocate += detab(strings, clocate, TABSTOP);
}else if(c == '\n'){
printf("%s\n", strings);
cleararray(strings);
clocate = 0;
}else{
strings[clocate] = c;
clocate++;
}
}
}
int detab(char strings[], int clocate, int n){
int i, j;
i = (n - (clocate % n));
for(j = 0; j < i; j++){
strings[clocate + j] = ' ';
}
return i;
}
void cleararray(char array[]){
int i;
for(i = 0; i < MAXCHAR; i++){
array[i] = '\0';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment