이 함수 validate_args는 프로그램의 인자를 검증하고 처리하는 역할을 합니다. 주요 기능은 다음과 같습니다:
인자 처리 및 초기화
ps_all_join 함수를 사용해 모든 인자를 하나의 문자열로 결합합니다.
ps_size_check 함수로 공백을 기준으로 나눈 인자의 개수를 확인합니다.
ft_split 함수로 결합된 문자열을 공백을 기준으로 분리합니다.
각 인자 검증
각 인자에 대해 다음 과정을 수행합니다:
ps_valid_atoi 함수로 유효한 정수인지 확인합니다.
유효하지 않으면 ps_error 함수를 호출하여 오류 처리합니다.
ps_atoi 함수로 문자열을 정수로 변환합니다.
get_new_node 함수로 새 노드를 생성합니다.
overlap_checker 함수로 중복된 값이 있는지 확인합니다.
메모리 관리
처리가 끝난 문자열과 노드는 즉시 free로 메모리를 해제합니다.
모든 처리가 끝난 후 tmp 배열의 메모리를 해제합니다.
주요 특징
문자열 처리, 메모리 동적 할당, 정수 변환 등 다양한 작업을 수행합니다.
엄격한 인자 검증을 통해 프로그램의 안정성을 높입니다.
메모리 누수를 방지하기 위해 적절한 메모리 관리를 수행합니다.
이 함수는 프로그램의 초기 단계에서 입력 데이터의 유효성을 검사하고, 스택 구조에 사용될 수 있는 형태로 데이터를 준비하는 중요한 역할을 합니다.
This function validate_args is responsible for validating and processing the program's arguments. Its main functionalities are as follows:
Argument Processing and Initialization
Uses ps_all_join function to combine all arguments into a single string.
Checks the number of arguments split by spaces using ps_size_check function.
Splits the combined string into separate arguments based on spaces using ft_split function.
Validating Each Argument
For each argument, it performs the following steps:
Checks if it's a valid integer using ps_valid_atoi function.
If invalid, calls ps_error function for error handling.
Converts the string to an integer using ps_atoi function.
Creates a new node using get_new_node function.
Checks for duplicate values using overlap_checker function.
Memory Management
Immediately frees the memory of processed strings and nodes using free.
Frees the memory of the tmp array after all processing is complete.
Key Features
Performs various tasks including string processing, dynamic memory allocation, and integer conversion.
Enhances program stability through strict argument validation.
Implements proper memory management to prevent memory leaks.
This function plays a crucial role in the initial stages of the program by validating input data and preparing it in a form that can be used in the stack structure.
'C Language' 카테고리의 다른 글
상대적 순위의 인덱스로 변환 | Converting to index for relative order (2) | 2025.01.03 |
---|---|
스택값 내림차순 정렬확인 | checking if the list is sorted in descending order (0) | 2025.01.03 |
스택초기화 | Stack Initialization (2) | 2025.01.03 |
양수와 0인 경우 len값 1 증가 | increasing one for len when it's plus or zero (0) | 2025.01.03 |
while(*str) 이 있는데 if(*str)이 있는이유 | The reason of using if(*str) despite of while(*str) syntax below (0) | 2025.01.02 |