프로그래밍/C++
-
폴더 내 파일 찾아 읽기프로그래밍/C++ 2015. 1. 23. 14:21
1. VS용#include #include #include void main() { _finddata_t fd; long handle; int result = 1; if ((handle = _findfirst(path, &fd)) == -1) return; while (result != -1) { printf("file name : %s\n", fd.name); result = _findnext(handle, &fd); } _findclose(handle); } 2. 공용 (POSIX Standard) #include #include int main() { DIR* dirp; struct dirent* dp; dirp = opendir("."); while (dirp) { errno = 0; if ((d..
-
getline 함수프로그래밍/C++ 2015. 1. 7. 20:40
파일을 읽을 때 한 줄 씩 편하게 읽을 수 있는 함수. 리눅스에서도 윈도우에서도 자주 사용하는 함수로 파일과 관련되어 자주 보게된다. 함수명getline 개요#include ssize_t getline(char** lineptr, size_t* n, FILE* stream); lineptr : stream으로부터 읽어 들인 char*로 파일 내용이 저장되어 있다. n : lineptr의 동적할당 크기이다. stream : 파일 포인터 리턴값 : stream으로 부터 읽어들인 데이터의 실제 길이 getline은 stream으로부터 한 줄씩(개행문자까지) 읽어들이는 함수이다. 최초 사용시 lineptr이 NULL이고 n이 0일 경우 getline함수 내에서 동적할당을 한다. 이후 stream안에 있는 한 줄..
-
SQLite3 라이브러리 생성하기프로그래밍/C++ 2014. 11. 13. 15:13
많은 스마트폰 기기 및 OS에서 사용하는 DB는 바로 SQLite.매번 SQLite를 사용할 때 마다 기억이 나지 않으니 이 참에 블로그에 library 생성 방법을 작성하도록 한다. 먼저 sqlite 사이트 (여기클릭)에 접속하여 아래와 같이 두 종류를 다운 받는다. sqlite-amalgamation-201411111459.zip을 다운 sqlite-dll-win32-x86-3080701.zip을 다운 위에서 받은 두 개의 파일을 압축을 푼다. source와 dll, def파일이 들어있다. 자.이제 필요한 자료는 다 모였으니 lib를 만들어보자.먼저 프로젝트를 생성해야겠지. Win32프로젝트로 마음에 드는 이름의 프로젝트를 생성 다음으로 넘어가다가 이 화면에서는 무조건 DLL 및 빈 프로젝트로 설정하..
-
문자열에서 문자를 추출(strtok, strtok_r)프로그래밍/C++ 2014. 9. 12. 15:46
NAMEstrtok, strtok_r - extract tokens from stringsSYNOPSIS#include char *strtok(char *str, const char *delim);char *strtok_r(char *str, const char *delim, char **saveptr);DESCRIPTION문자열에서 구분자에 의해 분리 되는 문자열을 찾아내는 함수이다.strtok이나 strtok_r 모두 리턴값은 문자열에서 가장 먼저 찾은 (구분자에 의해 분리 된) 문자열이다.더이상 찾지 못할 때엔 NULL을 반환한다.EXAMPLE #include #include #include int main(int argc, char *argv[]) { char *str1, *str2, *token..
-
unsigned short만 사용하면 warning이 뜬다.프로그래밍/C++ 2014. 8. 29. 15:38
int main(void) { unsigned short int length = 10; printf("Enter length : "); scanf("%u", &length); printf("value is %u \n", length); return 0; } 위 소스를 컴파일 하면 아래와 같은 warning을 내뿜는다.warning: format ‘%u’ expects argument of type ‘unsigned int *’, but argument 2 has type ‘short unsigned int *’ [-Wformat] 결국 %u와 unsigned short와 타입(포맷)이 맞지 않는 다는 얘기이니 -Wformat 말고 직접 warning을 없애야 한다.Specifies that a follo..