Advertisement
utroz

ENTAB

Dec 25th, 2011
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.86 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define TAB 8
  5.  
  6. void entab(char *args);
  7. int tab_count(char *args, short i);
  8.  
  9. int main(void)
  10. {
  11.         char str[64]= "dsadsadsa         dsadasdsadsa";  (9 spaces between words)   //Input
  12.         // Output: dsadsadsa\t dsadasdsadsa
  13.        
  14.         entab(str);        
  15.         return 0;
  16. }
  17.  
  18. void entab(char *args)
  19. {
  20.         short i;
  21.        
  22.         for(i = 0; args[i]; i++) {
  23.     if(args[i] == ' ' && tab_count(args, i)) {
  24.             putchar('\\');
  25.             putchar('t');
  26.             i += (TAB - 1);
  27.     } else
  28.             putchar(args[i]);
  29.         }
  30. }
  31.  
  32. int tab_count(char *args, short i)
  33. {        
  34.         short count, j;
  35.  
  36.         for(j = count = 0; args[i] && j < TAB; j++, i++) {
  37.     if(args[i] == ' ')
  38.             count++;
  39.     else
  40.             return 0;
  41.         }
  42.        
  43.         return (count == TAB) ? 1 : 0;      
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement