Problem Statement
Solution
We need to take each character and check if it a tab and replace multiple spaces. Solution to above problem would look something like this.
#include <stdio.h> #define SPACE_FOR_TAB 4 int main() { int ch, i; while((ch = getchar()) != EOF) { if(ch == '\t') { for(i = 0; i < SPACE_FOR_TAB; i++) { putchar(' '); } }else{ putchar(ch); } } return 0; }
Links
- Next Article - K & R : Exercise 1.21 - Replace space with min tab - entab
- Previous Article - K & R : Exercise 1.19 - Reverse input line
- All Article - K & R Answer
No comments :
Post a Comment