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+
}
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

0 commit comments

Comments
 (0)