Created
August 9, 2019 02:34
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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