#include<stdio.h>
int myatoi(char[]);
void main()
{
char string[81];
int re;
printf("Enter the string: \n");
gets_s(string,81);
re=myatoi(string);
printf("result is %d", re);
}
int myatoi(char str[]) {
int i = 0, j = 0;
if (str[0] == '+' || str[0] == '-') {
while (str[i] != '\0') {
str[i] = str[i + 1];
i++;
}
}
//이 부분 이후에서 오류가 납니다.
int p = 0;
while (str[j] != '\0') {
if (str[j] >= '0' && str[j] <= '9') {
j++;
}
else {
while (str[p] == '\0') {
str[p] = str[p + 1];
p++;
}
}
}
int k = 0, t = 0, m = 1, result = 0;
while (str[i] != '\0') {
k++;
}
for (t; t < k; t++) {
m = m * 10;
}
i = 0;
while (str[i] != '\0') {
result = result + str[i] * m;
m = m / 10;
i++;
}
return result;
}
댓글 입력