Commits

Lucian Brănescu-Mihăilă committed 58e46e6

13, 14

  • Participants
  • Parent commits 9e0f057

Comments (0)

Files changed (3)

 CFLAGS=-Wall -g
 
-programs = ex1 ex3 ex4 ex5 ex6 ex7 ex8 ex9 ex10 ex11 ex12
+programs = ex1 ex3 ex4 ex5 ex6 ex7 ex8 ex9 ex10 ex11 ex12 ex13 ex14
 
 all: $(programs)
 
+#include <stdio.h>
+
+int main(int argc, char *argv[])
+{
+    if(argc != 2) {
+        printf("ERROR: You need one argument.\n");
+        // this is how you abort a program
+        return 1;
+    }
+
+    int i = 0;
+    for(i = 0; argv[1][i] != '\0'; i++) {
+        char letter = argv[1][i];
+
+        switch(letter) {
+            case 'a':
+            case 'A':
+                printf("%d: 'A'\n", i);
+                break;
+
+            case 'e':
+            case 'E':
+                printf("%d: 'E'\n", i);
+                break;
+
+            case 'i':
+            case 'I':
+                printf("%d: 'I'\n", i);
+                break;
+
+            case 'o':
+            case 'O':
+                printf("%d: 'O'\n", i);
+                break;
+
+            case 'u':
+            case 'U':
+                printf("%d: 'U'\n", i);
+                break;
+
+            case 'y':
+            case 'Y':
+                if(i > 2) {
+                    // it's only sometimes Y
+                    printf("%d: 'Y'\n", i);
+                }
+                break;
+
+            default:
+                printf("%d: %c is not a vowel\n", i, letter);
+        }
+    }
+
+    return 0;
+}
+#include <stdio.h>
+#include <ctype.h>
+
+// forward declarations
+int can_print_it(char ch);
+void print_letters(char arg[]);
+
+void print_arguments(int argc, char *argv[]) {
+    int i = 0;
+
+    for(i = 0; i < argc; i++) {
+        print_letters(argv[i]);
+    }
+}
+
+void print_letters(char arg[]) {
+    int i = 0;
+
+    for(i = 0; arg[i] != '\0'; i++) {
+        char ch = arg[i];
+
+        if(can_print_it(ch)) {
+            printf("'%c' == %d ", ch, ch);
+        }
+    }
+
+    printf("\n");
+}
+
+int can_print_it(char ch) {
+    return isalpha(ch) || isblank(ch);
+}
+
+
+int main(int argc, char *argv[]) {
+    print_arguments(argc, argv);
+    return 0;
+}