Skip to content

Commit d0b9eb7

Browse files
committed
Support C
1 parent 4513386 commit d0b9eb7

File tree

17 files changed

+224
-1
lines changed

17 files changed

+224
-1
lines changed

compiled_starters/c/.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

compiled_starters/c/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/shell.png)
2+
3+
This is a starting point for C solutions to the
4+
["Build Your Own Shell" Challenge](https://app.codecrafters.io/courses/shell/overview).
5+
6+
_Add a description of your course here_
7+
8+
**Note**: If you're viewing this repo on GitHub, head over to
9+
[codecrafters.io](https://codecrafters.io) to try the challenge.
10+
11+
# Passing the first stage
12+
13+
The entry point for your `shell` implementation is in `app/main.c`. Study and
14+
uncomment the relevant code, and push your changes to pass the first stage:
15+
16+
```sh
17+
git add .
18+
git commit -m "pass 1st stage" # any msg
19+
git push origin master
20+
```
21+
22+
Time to move on to the next stage!
23+
24+
# Stage 2 & beyond
25+
26+
Note: This section is for stages 2 and beyond.
27+
28+
1. Ensure you have `c (9.2)` installed locally
29+
1. Run `./your_shell.sh` to run your program, which is implemented in
30+
`app/main.c`.
31+
1. Commit your changes and run `git push origin master` to submit your solution
32+
to CodeCrafters. Test output will be streamed to your terminal.

compiled_starters/c/app/main.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <stdio.h>
2+
3+
int main() {
4+
// You can use print statements as follows for debugging, they'll be visible
5+
// when running tests
6+
printf("Logs from your program will appear here!\n");
7+
8+
// Uncomment this block to pass the first stage
9+
// printf("$ ");
10+
// fflush(stdout);
11+
12+
// Wait for user input
13+
char input[100];
14+
fgets(input, 100, stdin);
15+
return 0;
16+
}

compiled_starters/c/codecrafters.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Set this to true if you want debug logs.
2+
#
3+
# These can be VERY verbose, so we suggest turning them off
4+
# unless you really need them.
5+
debug: false
6+
7+
# Use this to change the C version used to run your code
8+
# on Codecrafters.
9+
#
10+
# Available versions: c-9.2
11+
language_pack: c-9.2

compiled_starters/c/your_shell.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
#
3+
# DON'T EDIT THIS!
4+
#
5+
# CodeCrafters uses this file to test your code. Don't make any changes here!
6+
#
7+
# DON'T EDIT THIS!
8+
set -e
9+
tmpFile=$(mktemp)
10+
gcc app/*.c -o $tmpFile
11+
exec $tmpFile "$@"

course-definition.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ languages:
1919
- slug: "go"
2020
- slug: "python"
2121
- slug: "rust"
22+
- slug: "c"
2223

2324
marketing:
2425
difficulty: medium
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

solutions/c/01-oo8/code/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/shell.png)
2+
3+
This is a starting point for C solutions to the
4+
["Build Your Own Shell" Challenge](https://app.codecrafters.io/courses/shell/overview).
5+
6+
_Add a description of your course here_
7+
8+
**Note**: If you're viewing this repo on GitHub, head over to
9+
[codecrafters.io](https://codecrafters.io) to try the challenge.
10+
11+
# Passing the first stage
12+
13+
The entry point for your `shell` implementation is in `app/main.c`. Study and
14+
uncomment the relevant code, and push your changes to pass the first stage:
15+
16+
```sh
17+
git add .
18+
git commit -m "pass 1st stage" # any msg
19+
git push origin master
20+
```
21+
22+
Time to move on to the next stage!
23+
24+
# Stage 2 & beyond
25+
26+
Note: This section is for stages 2 and beyond.
27+
28+
1. Ensure you have `c (9.2)` installed locally
29+
1. Run `./your_shell.sh` to run your program, which is implemented in
30+
`app/main.c`.
31+
1. Commit your changes and run `git push origin master` to submit your solution
32+
to CodeCrafters. Test output will be streamed to your terminal.

solutions/c/01-oo8/code/app/main.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <stdio.h>
2+
3+
int main() {
4+
printf("Logs from your program will appear here!\n");
5+
6+
printf("$ ");
7+
fflush(stdout);
8+
9+
// Wait for user input
10+
char input[100];
11+
fgets(input, 100, stdin);
12+
return 0;
13+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Set this to true if you want debug logs.
2+
#
3+
# These can be VERY verbose, so we suggest turning them off
4+
# unless you really need them.
5+
debug: false
6+
7+
# Use this to change the C version used to run your code
8+
# on Codecrafters.
9+
#
10+
# Available versions: c-9.2
11+
language_pack: c-9.2

solutions/c/01-oo8/code/your_shell.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
#
3+
# DON'T EDIT THIS!
4+
#
5+
# CodeCrafters uses this file to test your code. Don't make any changes here!
6+
#
7+
# DON'T EDIT THIS!
8+
set -e
9+
tmpFile=$(mktemp)
10+
gcc app/*.c -o $tmpFile
11+
exec $tmpFile "$@"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
@@ -1,16 +1,13 @@
2+
#include <stdio.h>
3+
4+
int main() {
5+
- // You can use print statements as follows for debugging, they'll be visible
6+
- // when running tests
7+
printf("Logs from your program will appear here!\n");
8+
9+
- // Uncomment this block to pass the first stage
10+
- // printf("$ ");
11+
- // fflush(stdout);
12+
+ printf("$ ");
13+
+ fflush(stdout);
14+
15+
// Wait for user input
16+
char input[100];
17+
fgets(input, 100, stdin);
18+
return 0;
19+
}

solutions/c/01-oo8/explanation.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
The entry point for your Shell implementation is in `app/main.c`.
2+
3+
Study and uncomment the relevant code:
4+
5+
```c
6+
// Uncomment this block to pass the first stage
7+
printf("$ ");
8+
fflush(stdout);
9+
```
10+
11+
Push your changes to pass the first stage:
12+
13+
```
14+
git add .
15+
git commit -m "pass 1st stage" # any msg
16+
git push origin master
17+
```

starter-repository-definitions.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,19 @@
6161
template_attributes:
6262
required_executable: "go (1.19)"
6363
user_editable_file: "cmd/myshell/main.go"
64+
65+
- language: c
66+
file_mappings:
67+
- source: starter_templates/README.md
68+
target: README.md
69+
- source: starter_templates/codecrafters.yml
70+
target: codecrafters.yml
71+
- source: starter_templates/c/your_shell.sh
72+
target: your_shell.sh
73+
- source: starter_templates/c/app/main.c
74+
target: app/main.c
75+
- source: starter_templates/.gitattributes
76+
target: .gitattributes
77+
template_attributes:
78+
required_executable: "c (9.2)"
79+
user_editable_file: "app/main.c"

starter_templates/c/app/main.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <stdio.h>
2+
3+
int main() {
4+
// You can use print statements as follows for debugging, they'll be visible
5+
// when running tests
6+
printf("Logs from your program will appear here!\n");
7+
8+
// Uncomment this block to pass the first stage
9+
// printf("$ ");
10+
// fflush(stdout);
11+
12+
// Wait for user input
13+
char input[100];
14+
fgets(input, 100, stdin);
15+
return 0;
16+
}

starter_templates/c/your_shell.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
#
3+
# DON'T EDIT THIS!
4+
#
5+
# CodeCrafters uses this file to test your code. Don't make any changes here!
6+
#
7+
# DON'T EDIT THIS!
8+
set -e
9+
tmpFile=$(mktemp)
10+
gcc app/*.c -o $tmpFile
11+
exec $tmpFile "$@"

starter_templates/codecrafters.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,8 @@ language_pack: go-1.22
1818
{{# language_is_rust }}
1919
# Available versions: rust-1.77
2020
language_pack: rust-1.77
21-
{{/ language_is_rust }}
21+
{{/ language_is_rust }}
22+
{{# language_is_c }}
23+
# Available versions: c-9.2
24+
language_pack: c-9.2
25+
{{/ language_is_c }}

0 commit comments

Comments
 (0)