Skip to content

Commit 89e0f45

Browse files
committed
Initial commit
0 parents  commit 89e0f45

File tree

5 files changed

+77
-0
lines changed

5 files changed

+77
-0
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Command line application template for C
2+
3+
Implement CLI application by editing [main.c](src/main.c).
4+
You may add new files to keep your code clean, if it is allowed in your challenge.
5+
6+
## How to get input parameters
7+
You can get arguments with ordinary C way, using `int argc` and `char * argv[]`.
8+
9+
```c
10+
int main(int argc, char * argv[])
11+
{
12+
// code to run
13+
return 0;
14+
}
15+
```
16+
17+
## How to output result
18+
You can use `printf`.
19+
20+
``` c
21+
printf ("argv[%i]: %s\n", i, argv[i]);
22+
```
23+
24+
## How to compile
25+
To compile, we are using [clang](http://clang.llvm.org/) gcc command.
26+
27+
If you want to change compile option or etc, please edit [makefile](makefile).

README_ja.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# コマンドラインアプリケーション(CLI アプリ)作成用テンプレート(C)
2+
3+
[main.c](src/main.c)を編集して、CLIアプリを実装してください。
4+
チャレンジ内でファイルの作成が許可されていれば、可読性等のためにファイルを分割する事も可能です。
5+
6+
## コマンドライン引数の取得方法
7+
通常のC++アプリケーションと同じように、`int argc``char * argv[]` を使用してください。
8+
9+
```c
10+
int main(int argc, char * argv[])
11+
{
12+
// code to run
13+
return 0;
14+
}
15+
```
16+
17+
## コマンド実行結果の標準出力への出力
18+
printf等標準出力に出力する任意のメソッドが使用可能です。
19+
20+
``` c
21+
printf ("argv[%i]: %s\n", i, argv[i]);
22+
```
23+
24+
## コンパイルについて
25+
コンパイルには[clang](http://clang.llvm.org/)のgccコマンドを使用しています。
26+
27+
コンパイルオプション等を変更する場合は[makefile](makefile)を変更してください。

cli-template.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
build:
2+
- make
3+
files:
4+
- makefile
5+
- src/main.c
6+
main: src/main.c
7+
command: ./main
8+
envConf:
9+
imageName: "givery/track-base2"

makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
main: src/*.c
2+
gcc -o main src/*.c
3+
clean:
4+
rm main

src/main.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <stdio.h>
2+
3+
int main(int argc, char *argv[])
4+
{
5+
// start from 1 to ignore script name; argv[0] will be a name of processing file.
6+
for (int i = 1; i < argc; i++) {
7+
printf ("argv[%i]: %s\n", i, argv[i]);
8+
}
9+
return 0;
10+
}

0 commit comments

Comments
 (0)