samir82show

spaces to tabs

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