SRC 2
SRC 2
1 #include <stdio.h>
2
3 int main(void)
4 {
5 printf("hello, world\n");
6 }
hello1.c
1 #include <cs50.h>
2 #include <stdio.h>
3
4 int main(void)
5 {
6 string name = get_string("What's your name? ");
7 printf("hello, %s\n", name);
8 }
buggy0.c
1 // Prints chars
2
3 #include <stdio.h>
4
5 int main(void)
6 {
7 char c1 = 'H';
8 char c2 = 'I';
9 char c3 = '!';
10
11 printf("%c%c%c\n", c1, c2, c3);
12 }
hi1.c
1 // Prints string
2
3 #include <cs50.h>
4 #include <stdio.h>
5
6 int main(void)
7 {
8 string s = "HI!";
9 printf("%s\n", s);
10 }
hi3.c
1 // Multiple strings
2
3 #include <cs50.h>
4 #include <stdio.h>
5
6 int main(void)
7 {
8 string s = "HI!";
9 string t = "BYE!";
10
11 printf("%s\n", s);
12 printf("%s\n", t);
13 }
hi6.c
1 // Array of strings
2
3 #include <cs50.h>
4 #include <stdio.h>
5
6 int main(void)
7 {
8 string words[2];
9
10 words[0] = "HI!";
11 words[1] = "BYE!";
12
13 printf("%s\n", words[0]);
14 printf("%s\n", words[1]);
15 }
hi7.c
1 #include <cs50.h>
2 #include <stdio.h>
3
4 int main(void)
5 {
6 string words[2];
7
8 words[0] = "HI!";
9 words[1] = "BYE!";
10
11 printf("%c%c%c\n", words[0][0], words[0][1], words[0][2]);
12 printf("%c%c%c%c\n", words[1][0], words[1][1], words[1][2], words[1][3]);
13 }
length0.c
1 // Uppercases a string
2
3 #include <cs50.h>
4 #include <stdio.h>
5 #include <string.h>
6
7 int main(void)
8 {
9 string s = get_string("Before: ");
10 printf("After: ");
11 for (int i = 0, n = strlen(s); i < n; i++)
12 {
13 if (s[i] >= 'a' && s[i] <= 'z')
14 {
15 printf("%c", s[i] - 32);
16 }
17 else
18 {
19 printf("%c", s[i]);
20 }
21 }
22 printf("\n");
23 }
uppercase1.c
1 // Uses get_string
2
3 #include <cs50.h>
4 #include <stdio.h>
5
6 int main(void)
7 {
8 string answer = get_string("What's your name? ");
9 printf("hello, %s\n", answer);
10 }
greet1.c