Desc :

 

int atot ( const char* string );

문자열을 받아서 숫자로 변환해준다

(공백, 탭, 기호 +-, 숫자만 변환한다, 문자와 숫자가 섞여있으면 숫자만 변환되고 나머지 버려진다)


Source Code :

#include <stdio.h>
#include <stdlib.h>

void main()
{
	int count;
	int total = 0;
	char string[100];

	for (count = 1; count <= 3; count++)
	{
		printf("%d번째 문자열을 입력한 후 Enter키를 누르세요\n", count);

		gets(string);

		total += atoi(string);

		printf("입력 값 = %d, 총 합 = %d\n", atoi(string), total);
	}

	printf("읽은 문자열의 총 합은 %d입니다.\n", total);
}

 


Result :

+ Recent posts