Skip to content

Instantly share code, notes, and snippets.

@gotjon05
Created August 9, 2019 02:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gotjon05/fddeb3cb35679e1c40301fdcc121d6bf to your computer and use it in GitHub Desktop.
Save gotjon05/fddeb3cb35679e1c40301fdcc121d6bf to your computer and use it in GitHub Desktop.
Write a program detab that replaces tabs in the input with the proper number of blanks to space for the next tab stop
#include <stdio.h>
#define MAXLINE 1000
#define TAB 8
int getlines(char line[], int maxline);
void detab(char line[], int array_size);
int main()
{
char line[MAXLINE];
int array_size;
while(array_size = getlines(line, MAXLINE)){
detab(line, array_size);
printf("%s", line);
}
}
int getlines(char line[], int maxline)
{
int c, i;
for(i = 0; i<maxline-1 && (getchar())!=EOF && c !='\n'; i++){
line[i] = c;
}
line[i] = '\0';
return i;
}
void detab(char line[], int array_size)
{
int i;
for(i=0; i<array_size; i++){
if(line[i] == '\t'){
line[i] = " ";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment