1. Cédric Bonhomme
  2. awk-scripts

Commits

Cédric Bonhomme  committed a828602

  • Participants
  • Parent commits 7cac789
  • Branches default

Comments (0)

Files changed (1)

File Home.wiki

View file
  • Ignore whitespace
 #!bash
 
 $ awk -f indent_C_source.awk test_files/indent_C_source.txt
-main (int argc, char * argv[])
+int main(int argc, char *argv[])
 {
-        for(i=1;i<=100;i++)
-        if (i==2)
+        char buffer[BUFSIZ];
+        int i;
+
+        if (argc != 3)
+        error("arg");
+        if (strlen(argv[1]) != 1 || strlen(argv[2]) != 1)
+        error("arg");
+        while (fgets(buffer, BUFSIZ, stdin) != NULL)
         {
-                if (i % 3 == 0)
+                for (i = 0; i < strlen(buffer); i++)
                 {
-                        printf("Have fun !");
+                        if (buffer[i] == argv[1][0])
+                        buffer[i] = argv[2][0];
                 }
+                if (fputs(buffer, stdout) == -1)
+                error("fputs");
         }
+        return (0);
 }
-
 }}}