본문 바로가기

42cursus17

개행으로 끝나느냐, 개행으로 끝나지 않느냐 hi, hello('\n') hi, wins // hi, hello('\n') hi, wins('\n') // 두 문단을 gnl로 읽었을 때 차이점은 line의 맨마지막줄이 '\0'로 끝나는지 아닌지 차이 #include "get_next_line_bonus.h" #include #include int main() { int fd; int ret; char *line; fd = open("./test", O_RDONLY); while ((ret = get_next_line(fd, &line)) > 0) { printf("%s\n",line); free(line); } printf("%s\n",line); free(line); return(0); } main.c 함수로 실행시켜보면, 마지막에 한줄에 '\0.. 2020. 7. 22.
get_next_line(bonus) 이중배열과 배열 포인터에 대한 이해 gnl의 bonus를 진행하기 위해서는 이중배열 char buffer[fd][BUFFER_SIZE + 1]을 memset할 수 있어야했다. -> 가능하다.!! (이중배열을 써야하는 건가? (BUFFER_SIZE+1) * fd 이면 값이 꽤나 많이 클 것으로 예상됨) char buffer_double[5][20]; memset(buffer_double[1], 0, 20); printf("&buffer_double[2][0] p : %p\n", &buffer_double[2][0]); printf("&buffer_double[2] p : %p\n", &buffer_double[2]); printf("buffer_double[2][0] p : %p\n", buffer_dou.. 2020. 7. 11.
printf_check-list 1. 서식문자열에서 서식태그와 가변인자로 넣어주는 개수가 일치하지 않을 때 (printf와 ft_printf 모두 동일하게 서식문자와 서식태그에 대응 값만 출력되고 나머지는 무시한다.) gcc -Wall -Wextra -Werror 에서 에러로 표현해주기때문에, 이러한 경우는 배제하기로한다. 2. 모든 정보는 결국 bit로 저장된다. -> signed unsigned도 값이 다르게 보여도 실제 bit값은 동일하다. 읽는 byte의 범위가 다르거나, 읽어서 해석하는 방법이 다를 뿐이다. int 는 ft_itoa로 해결가능하지만, unsigned int 는 다른 방법으로 해결해야한다. ->ft_utoa.c 새로 만듦 3. flag처리 정확도 s 넓이(width) cspdiuxX%(all) 넓이에 0채움 pd.. 2020. 7. 10.
printf 자료조사 Variadic function Variadic function : function that takes a arbitrarily many argument. "The C function printf and the Common Lisp function format are two such examples. Both take one argument that specifies the formatting of the output, and any number of arguments that provide the values to be formatted."[1] Variadic functions can expose type-safety problems in some languages. high-severity secu.. 2020. 7. 6.