본문 바로가기

분류 전체보기

[C++] 입력함수 cin은 데이터 타입에 따라 받을수 있고, getline은 문자열로 한줄로 받을때 용이하다 cin getline 읽어오는 대상 데이터(int, char, string...) string 언제까지? 개행문자(\n) 개행문자(\n) 구분자 공백 문자(공백, 탭, 개행) 구분 없음 #include int main() { intnum1; floatnum2; charletter; std::cin >> num1 >> num2 >> letter; std::cout 더보기
[자료구조] deque double-ended queue 정의 양쪽 말단에서 데이터의 삽입과 삭제가 가능한 자료구조. 강점 - 양쪽 말단에서 데이터의 삽입 삭제를 상수시간안에 해낼수 있다. - 배열과 비교해보자면, 배열의 경우 최상단에 데이터를 추가할경우, 그 외의 모든 데이터를 shifting 해야 하는데, 이는 꽤 많은 시간을 요한다 - 네트위크 통신 프로토콜 같은곳에서 용이하게 사용됨. 약점 - doubly linked list로 구현한 경우, memory overhead의 위험성 존재. - 말단에 데이터를 추가할때마다, 새로운 포인터를 필요로 하는데, 이것이 문제를 야기할 가능성 있음. - array로 구현한 경우, 삽입과 삭제시 모든 데이터를 shifting 해줘야 함 - 이것은 많은 시간을 요함. 구현 보통 arra.. 더보기
[42Seoul] so_long Summary: This project is a very small 2D game. Its purpose is to make you work with textures, sprites, and some other very basic gameplay elements. Common Instructions Program name so_long Turn in files Makefile, *.h, *.c, maps, testures Makefile Name, all, clean, fclean, re Arguments A map in format *.ber External functs. - open ,close, read, write - malloc, free, perror, strerror, exit - All f.. 더보기
[언어공부] <c> free()와 NULL포인터 개요 void free(void *ptr) 동적할당된 메모리를 해제한다. 주의할 점 동적할당된 메모리가 아니라면 free()할수 없다. #include int main() { char *str = "hello"; free(str) } //-----result------------ /* free(): invalid pointer signal: aborted (core dumped) */ 매개변수로 받은 경우 free()를 했다면, 해당 메모리가 해제되었다는것을 알려주기위해, 그 포인터를 NULL포인터로 만들어야 한다. free()의 경우 둘 모두 정상적으로 작동했다. 하지만, 전자의 경우 포인터가 NULL포인터가 되지않은걸 알수 있다. 함수의 매개변수로 문자열의 주소를 줬는데, 이는 값을 준것이고, str.. 더보기
[언어 공부] <c++> vector 개요 std::vector is a sequence container that encapsulates dynamic size arrays. 특징 배열처럼 연속적으로 저장됨. 그 크기는 자동으로 관리됨.(확장 가능) 배열(array)과 비교 vector는 크기를 자유롭게 늘릴수 있어, 배열에 비해 유연 사용 라이브러리 #include 선언 vector n_a_m_e(n) n : 벡터 공간의 크기 예제 #include #include using namespace std; int main() { vector list(6);//벡터 선언. 파라미터는 공간 크기. vector horse(6); horse[0] = 1; horse[1] = 1; horse[2] = 2; horse[3] = 2; horse[4] = .. 더보기
ft_printf.c program name libftprintf.a External functs. malloc, free, wirte, va_start, va_arg, va_copy, va_end Description 오리지널 printf()를 흉내내는 ft_printf() 구현 prototype ft_printf(const char *, ...); Mandatory 오리지널 printf()의 버퍼는 구현하지 않는다. cspdiuxX% 옵션을 handle 한다. %c : character 출력 %s : string 출력 %p : void * 포인터 출력 %d : 10진법 숫자 출력 %i : 10진법 정수 출력 %u : unsigned 10진법 숫자 출력 %x : 16진법 숫자를 소문자로 출력 %X : 16진법 숫자를 대문자.. 더보기
get_next_line.c 과제 Function name get_next_line Prototype char *get_next_line(int fd); Parameters fd : the file descriptor to read from Return Read line : correct behavior NULL : there is nothing else to read, or an error occurred Description Write a function that returns a line read from a file descriptor External functs. read, malloc, free 지시사항 - get_next_lint()함수를 반복 호출해서 fd로부터 가리켜진 텍스트 파일을 읽어야함. 한번에 한줄씩 - 읽어.. 더보기