본문 바로가기

컴퓨터

문자열 연산자 - strcpy, strncpy, strlen, strcat, strncat, strcmp, strncmp, strchar, strstr, atoi, atof, atol, strftime strcpy 이 함수는 특정 문자열에서 NULL 문자를 인식할때까지의 모든 데이터를 다른 곳으로 복사한다. char * strcpy(char * strDestination, const char * strSource); // NULL 문자를 만나기 전까지 strSource에서 strDestination로 복사한다. ex> char string[5] = {0}; strcpy(string, "1234567890"); //컴파일은 정상으로 되나 실재 사용에서 에러가 날수있다. 그 이유는 overflow가 일어나기 때문으로 복사시 해당배열을 넘어도 메모리상의 배열과 붙어있는 영역에 복사를 한다. 이때 다른영역을 건드리기때문에 그 영역을 사용하지 않는다면 문제가 일어나지 않겠지만 그영역을 사용한다면 에러를 발생시킨.. 더보기
strlen, strcpy, strcat, strcmp 함수 구현 [소스] #include long strlen(const char *str) { const char *s; for (s = str; *s; ++s); return(s - str); } char *strcpy(char *to, const char *from) { char *save = to; for (; (*to = *from) != 0; ++from, ++to); return(save); } char *strcat(char *s, const char *append) { char *save = s; for (; *s; ++s); while ((*s++ = *append++) != 0); return(save); } int strcmp(const char *s1, const char *s2) { while (*s1 .. 더보기
malloc 메모리 할당 및 해제 / 재 할당 출처 : winapi.co.kr void *malloc(size_t size ); void free(void *memblock ); 먼저 malloc(엠얼록이라고 읽는다) 함수부터 알아보자. 인수로 필요한 메모리양을 바이트 단위로 전달하면 요청한만큼 할당한다. size_t는 메모리의 양을 나타내는 단위인데 _t로 끝나는 사용자 정의 타입은 표준에 의해 반드시 정의하도록 되어 있으므로 기본 타입과 거의 대등한 자격을 가진다. 플랫폼에 따라 다르게 정의되어 있는데 대부분의 32비트 컴파일러들은 size_t를 unsigned의 부호없는 정수형으로 정의한다. 따라서 이 함수로 할당할 수 있는 이론적 최대 용량은 4G 바이트라고 할 수 있다. 10바이트가 필요하면 malloc(10)이라고 호출하고 1000바이트가.. 더보기
배열 stack / 단순연결리스트 stack /***********************************************/ // ex. 1 배열스택 /***********************************************/ #include #include #define STACK_SIZE 5 int stack[STACK_SIZE]; int top; // stack공간에 값이 저장되어 있는 최상단의 위치값 int getnum(void); void init_stack(void); void push(int data); int pop(void); void print_stack(void); void all_data_delete(void); void main(void) { int menu, num; // stack 초기화 init_s.. 더보기
[스크랩] syntaxhighlighter를 tistory에서 사용 하는 방법. 블로그에 프로그램 소스 코드를 입력할때 깔끔하게 입력할 수 있도록 해주는 자바스크립트 라이브러리 syntaxhighlighter를 적용하는 방법. 라이브러리는 이곳에서 다운받을 수 있다. syntaxhighter란 홈페이지에 있는 소스코드를 아래와 같이 색상으로 구문 강조를 해 주는 기능 입니다. #include int main( int argc, const char* argv[] ) { printf( "\nHello World\n\n" ); } 우선 아래 주소에 가서 현재 최신 버전인 SyntaxHighlighter_1.5.1.rar를 다운 받습니다. http://code.google.com/p/syntaxhighlighter/ 가기도 귀찮으신 분은 아래 파일을 다운로드 받으시면 됩니다. 다운로드 : .. 더보기
Visual C++ 자주 쓰이는 단축키 모음 Visual C++ 단축키 모음 일반 Editor 에서… Ctrl + Space : 인텔리센스 출력 Ctrl + F5 : 빌드 후 프로그램 실행 F5 : Debugging 모드로 작동 F9 : Break Point Ctrl + F2 : 북마크 F2 : 북마크로 이동 F10 : Debugging 모드로 작동하되 엔트리 포인트부터 시작 Ctrl + F10 : Debugging 모드로 작동하되 커서의 위치까지 Alt + F8 : 들여쓰기 정리 Ctrl + Shite + Space : 현재 가르키고 있는 함수의 매개변수 보기 Alt + B -> E : Clean Alt + B -> R : Rebuild All Ctrl + E : 현재 괄호랑 맞는 괄호를 찾아준다. Alt + F7 : Project Setting.. 더보기
Visual C++ 6.0 단축키 Visual C++ 6.0 단축키 단축키 설명 Ctrl + N New Ctrl + O Open Ctrl + S Save Ctrl + P Print Ctrl + Tab Edit하고 있는 Child Window 간의 이동 Ctrl + F4 현재 Edit하고 있는 Child Window를 닫기 Ctrl + Z Undo Ctrl + Y Redo Ctrl + X Cut Ctrl + C Copy Ctrl + V Paste Del Delete Ctrl + A Select All Ctrl + F Find Ctrl + H Replace Ctrl + G Go To Alt + F2 Bookmarks Alt + F9 Breakpoints Ctrl + I Incremental Search Alt + F8 Format Selec.. 더보기
IPv4 주소를 IPv6 주소로 변환 #ifdef WIN32 # pragma comment(lib, "ws2_32.lib") # include # include #else #endif #include /** @code RFC 3493 3.7 Compatibility with IPv4 Nodes The IPv4 address is encoded into the low-order 32 bits of the IPv6 address, and the high-order 96 bits hold the fixed prefix 0:0:0:0:0:FFFF. IPv4-mapped addresses are written as follows: ::FFFF: @endcode */ struct in_addr6 IPv4ToIPv6(struct in_addr IPv4).. 더보기