Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Exercise 1-20. Write a program detab that
- replaces tabs in the input with the proper
- number of blanks to space to the next tab
- stop. Assume a fixed set of tab stops, say
- every n columns. Should n be a variable or
- a symbolic parameter?*/
- #include <stdio.h>
- #define MAX 1000
- char str[MAX];
- int detab(int len);
- int main()
- {
- int len;
- while ((len = detab(MAX)) > 0)
- printf("%s\n", str);
- return 0;
- }
- int detab(int len) {
- int c, i, j, t, temp, remainder;
- i = t = j = remainder = 0;
- while ((c = getchar()) != EOF && c != '\n' && i < len - 1 ) {
- if (i > 8)
- remainder= i % 8;
- if (c != '\t') {
- if (t) {
- if (i > 8) {
- while (j < (t - remainder)) {
- str[i++] = ' ';
- j++;
- }
- } else {
- temp = i;
- while (j < (t - temp)) {
- str[i++] = ' ';
- j++;
- }
- }
- t = j = 0;
- }
- str[i++] = c;
- } else
- t += 8;
- }
- if (t) {
- if (i > 8) {
- while (j < (t - remainder)) {
- str[i++] = ' ';
- j++;
- }
- } else {
- temp = i;
- while (j < (t - temp)) {
- str[i++] = ' ';
- j++;
- }
- }
- }
- str[i] = '\0';
- return i;
- }
Advertisement
Add Comment
Please, Sign In to add comment