diff options
Diffstat (limited to 'wk2/lect')
-rw-r--r-- | wk2/lect/greet.c | 10 | ||||
-rw-r--r-- | wk2/lect/lowercase.c | 15 | ||||
-rw-r--r-- | wk2/lect/status.c | 16 | ||||
-rw-r--r-- | wk2/lect/uppercase.c | 21 |
4 files changed, 62 insertions, 0 deletions
diff --git a/wk2/lect/greet.c b/wk2/lect/greet.c new file mode 100644 index 0000000..ccecd7d --- /dev/null +++ b/wk2/lect/greet.c @@ -0,0 +1,10 @@ +#include <stdio.h> +#include <cs50.h> + +//argc is argument count, ie how many arguments were given +//argv is an array of the arguments given +//argv[0] is the command that calls the script, ie ./greet +int main(int argc, string argv[]) +{ + printf("hello, %s\n", argv[1]); +} diff --git a/wk2/lect/lowercase.c b/wk2/lect/lowercase.c new file mode 100644 index 0000000..ee473ae --- /dev/null +++ b/wk2/lect/lowercase.c @@ -0,0 +1,15 @@ +#include <stdio.h> +#include <ctype.h> +#include <cs50.h> +#include <string.h> + +int main(void) +{ + string s = get_string("Before: "); + printf("After: "); + for (int i = 0, n = strlen(s); i < n; i++) + { + printf("%c", tolower(s[i])); + } + printf("\n"); +} diff --git a/wk2/lect/status.c b/wk2/lect/status.c new file mode 100644 index 0000000..ebce04c --- /dev/null +++ b/wk2/lect/status.c @@ -0,0 +1,16 @@ +#include <stdio.h> +#include <cs50.h> + +int main(int argc, string argv[]) +{ + if (argc != 2) + { + printf("Missing command-line argument\n"); + return 1; + } + else + { + printf("hello, %s\n", argv[1]); + return 0; + } +} diff --git a/wk2/lect/uppercase.c b/wk2/lect/uppercase.c new file mode 100644 index 0000000..3a34b97 --- /dev/null +++ b/wk2/lect/uppercase.c @@ -0,0 +1,21 @@ +#include <stdio.h> +#include <cs50.h> +#include <string.h> + +int main(void) +{ + string s = get_string("Before: "); + printf("After: "); + for (int i = 0; i < strlen(s); i++) + { + if (s[i] >= 'a' && s[i] <= 'z') + { + printf("%c", s[i] - 32); + } + else + { + printf("%c", s[i]); + } + } + printf("\n"); +} |