質問編集履歴
3
c
test
CHANGED
File without changes
|
test
CHANGED
@@ -33,18 +33,6 @@
|
|
33
33
|
|
34
34
|
### 該当コード全て
|
35
35
|
```c
|
36
|
-
/* ************************************************************************** */
|
37
|
-
/* */
|
38
|
-
/* ::: :::::::: */
|
39
|
-
/* ft_atoi_base.c :+: :+: :+: */
|
40
|
-
/* +:+ +:+ +:+ */
|
41
|
-
/* By: shogura <shogura@student.42tokyo.jp> +#+ +:+ +#+ */
|
42
|
-
/* +#+#+#+#+#+ +#+ */
|
43
|
-
/* Created: 2022/02/18 14:03:10 by shogura #+# #+# */
|
44
|
-
/* Updated: 2022/02/18 14:42:31 by shogura ### ########.fr */
|
45
|
-
/* */
|
46
|
-
/* ************************************************************************** */
|
47
|
-
|
48
36
|
#include <stdio.h>
|
49
37
|
int base_check(char *base)
|
50
38
|
{
|
2
add code
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
### 該当コード
|
1
|
+
### 該当コード(一部抜粋)
|
2
2
|
関数に渡された文字列に空白やマイナス、プラス記号があった場合左にずらしてこれらの記号を消したいのですがバスエラーがでてしまいうまく動作しません。どこが原因なのでしょうか?
|
3
3
|
|
4
4
|
※2連続で記号が来た場合jを初期化しないとダメですがそこは一回保留で1つだけ記号がある場合を考えてます
|
@@ -30,3 +30,76 @@
|
|
30
30
|
return (len);
|
31
31
|
}
|
32
32
|
```
|
33
|
+
|
34
|
+
### 該当コード全て
|
35
|
+
```c
|
36
|
+
/* ************************************************************************** */
|
37
|
+
/* */
|
38
|
+
/* ::: :::::::: */
|
39
|
+
/* ft_atoi_base.c :+: :+: :+: */
|
40
|
+
/* +:+ +:+ +:+ */
|
41
|
+
/* By: shogura <shogura@student.42tokyo.jp> +#+ +:+ +#+ */
|
42
|
+
/* +#+#+#+#+#+ +#+ */
|
43
|
+
/* Created: 2022/02/18 14:03:10 by shogura #+# #+# */
|
44
|
+
/* Updated: 2022/02/18 14:42:31 by shogura ### ########.fr */
|
45
|
+
/* */
|
46
|
+
/* ************************************************************************** */
|
47
|
+
|
48
|
+
#include <stdio.h>
|
49
|
+
int base_check(char *base)
|
50
|
+
{
|
51
|
+
int i;
|
52
|
+
int j;
|
53
|
+
|
54
|
+
i = 0;
|
55
|
+
j = i + 1;
|
56
|
+
while (base[i] == '\0')
|
57
|
+
{
|
58
|
+
if (base[i] == '+' || base[i] == '-')
|
59
|
+
return (0);
|
60
|
+
while (base[j] != '\0')
|
61
|
+
{
|
62
|
+
if (base[i] == base[j])
|
63
|
+
return (0);
|
64
|
+
j++;
|
65
|
+
}
|
66
|
+
i++;
|
67
|
+
}
|
68
|
+
return (1);
|
69
|
+
}
|
70
|
+
|
71
|
+
int ft_atoi_base(char *str, char *base)
|
72
|
+
{
|
73
|
+
int num[256];
|
74
|
+
int base_s;
|
75
|
+
int sum;
|
76
|
+
int minus;
|
77
|
+
int i;
|
78
|
+
int j;
|
79
|
+
|
80
|
+
i = 0;
|
81
|
+
j = 0;
|
82
|
+
minus = 1;
|
83
|
+
if (!(base_check(base)))
|
84
|
+
return (0);
|
85
|
+
while (str[j] == '-' || str[j] == '+' || str[j] == ' ')
|
86
|
+
{
|
87
|
+
if (str[j] == '-')
|
88
|
+
minus *= -1;
|
89
|
+
j++;
|
90
|
+
}
|
91
|
+
while ((str[i++] = str[j++]) != '\0');
|
92
|
+
printf("%s ", str);
|
93
|
+
|
94
|
+
return (0);
|
95
|
+
}
|
96
|
+
|
97
|
+
int main(void)
|
98
|
+
{
|
99
|
+
int num;
|
100
|
+
num = ft_atoi_base("-1234", "0123456789"); // A798BF(16) → 10983615(10)
|
101
|
+
printf("%d", num);
|
102
|
+
return 0;
|
103
|
+
}
|
104
|
+
|
105
|
+
```
|
1
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -17,3 +17,16 @@
|
|
17
17
|
i++;
|
18
18
|
}
|
19
19
|
```
|
20
|
+
|
21
|
+
dititを求める関数
|
22
|
+
```c
|
23
|
+
int ft_len(char *base) //to check base
|
24
|
+
{
|
25
|
+
int len;
|
26
|
+
|
27
|
+
len = 0;
|
28
|
+
while (base[len] != '\0')
|
29
|
+
len++;
|
30
|
+
return (len);
|
31
|
+
}
|
32
|
+
```
|