summaryrefslogtreecommitdiff
path: root/rush/test.c
diff options
context:
space:
mode:
Diffstat (limited to 'rush/test.c')
-rw-r--r--rush/test.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/rush/test.c b/rush/test.c
new file mode 100644
index 0000000..051d840
--- /dev/null
+++ b/rush/test.c
@@ -0,0 +1,43 @@
+// カスタム化されたヘッダーファイルを使用するため
+// unistad.hにwrite関数が含まれているため、ヘッダーファイルを追加した
+// テスト用にprintfを24及び40行目に配置、そのためstdio.hを追加。提出時は削除またはアウト
+#include "ft_main.h"
+#include <unistd.h>
+#include <stdio.h>
+// *char_to_int関数はChar型からInt型に変えるための自作関数
+// Charポインタ型およびIntポインタ型
+void char_to_int(char *str, int *box)
+{
+ int i;
+ int j;
+
+ i = 0;
+ j = 0;
+ // 変数StrはArgvの先頭を指している。先頭からi文字後を添字[]でアクセスしている。
+ while (str[j] != '\0')
+ {
+ // もし1から9までの文字の場合、BoxにChar型からIntに変換後に格納する。
+ if ('0' <= str[j] && str[j] <= '9')
+ {
+ box[i] = str[j] - '0';
+ // 提出時は削除またはコメントアウト
+ // printf("%d",box[i]);
+ i++;
+ }
+ j++;
+ }
+}
+// 返却値の型はInt型ですよ。関数名はMain。
+// 引数はInt型Argc(コマンドライン引数の数)
+// 引数はCharダブルポインタ型のArgv(文字列配列型)
+int main(int argc, char *argv[])
+{
+ // Int型のBox_16を宣言[]内は要素の数を入力している
+ // Argv[1]はファイル名の後ろの空白の後ろの文字列(12345…)
+ int box_16[16];
+ char_to_int(argv[1],box_16);
+
+ // printf("\n%d",box_16[2]);
+
+ return (0);
+}