samir82show

tab to equivelant spaces

Nov 8th, 2013
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #include <stdio.h>
  2. #define MAXTSPACE 8
  3. int main()
  4. {
  5. int c, i, spacecnt;
  6. i = 0;
  7. spacecnt = MAXTSPACE;
  8.  
  9. while((c = getchar()) != EOF ) {
  10. if(c == '\t') {
  11. for(i = 0; i < spacecnt; ++i)
  12. printf(" ");
  13. spacecnt = MAXTSPACE;
  14. } else if(c == '\n') {
  15. spacecnt = MAXTSPACE;
  16. putchar(c);
  17. } else {
  18. putchar(c);
  19. --spacecnt;
  20. if(spacecnt > 1)
  21. spacecnt = MAXTSPACE;
  22. }
  23.  
  24. }
  25.  
  26. return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment