본문 바로가기
반응형

c언어23

파일 탐색하기 -인자로 전달된 디렉토리 경로로부터 파일을 탐색한다. ex:)SearchFile("C:\\*.*"); //C드라이브의 모든 파일을 탐색한다. #include #include #include #define BUFSIZE 512 void SearchFile(char* pPath){ struct _finddatai64_t c_file; intptr_t hFile; char dirPath[BUFSIZE]; char tempPath[BUFSIZE]; int i; //디렉토리 경로명만 추출하는 작업(현재 경로명에서 *.* 제거) strncpy(dirPath,pPath,BUFSIZE-1); i=strlen(dirPath)-4; dirPath[i]=0; //파일 탐색 시작 hFile=_findfirsti64(pPath.. 2011. 7. 4.
호스트 IP 주소 얻기 -인자로 전달한 문자열 포인터에 호스트 IP 주소를 저장한다. #include #include void GetHostIP(char* ip){ WORD wVersionRequested; WSADATA wsaData; char name[255]; PHOSTENT hostinfo; wVersionRequested = MAKEWORD(2,0); if(WSAStartup(wVersionRequested,&wsaData) == 0){ if(gethostname(name,sizeof(name)) ==0){ if((hostinfo = gethostbyname(name)) != NULL){ strcpy(ip,inet_ntoa(*(struct in_addr*)*hostinfo->h_addr_list)); } } } WSA.. 2011. 7. 4.
파일 다운로드 하기 -인자로 전달받은 URL로부터 파일을 다운로드 받습니다. ex:)GetFile("http://localhost/file.exe","c:\\file.exe"); //http://localhost/file.exe 에서 파일을 다운받아 c:\file.exe에 저장 #include #include BOOL GetFile(char* url,char* dstPath){ HRESULT hr; hr=URLDownloadToFile(NULL,url,dstPath,0,NULL); if(hr == S_OK){ return TRUE; } return FALSE; } 2011. 7. 4.
시스템 드라이브 목록 얻기 -현재 시스템의 드라이브 목록을 얻습니다. #include #include int main(){ int cnt; int i; int drvType; char drvRoot[104]; char path[7]="A:/*.*"; //드라이브 목록을 불러옴 cnt=GetLogicalDriveStrings(104,drvRoot); for(i=0;i 2011. 7. 4.
운영체제 정보 얻기 -현재 실행중인 운영체제의 정보를 얻습니다. #include #include void printOSInfo(){ OSVERSIONINFO info; info.dwOSVersionInfoSize=sizeof(OSVERSIONINFO); GetVersionEx(&info); printf("Major : %d\n",info.dwMajorVersion); printf("Minor : %d\n",info.dwMinorVersion); printf("ServicePack : %s\n",info.szCSDVersion); } 2011. 7. 4.
콘솔 텍스트 출력하기 -콘솔의 원하는 위치에 텍스트를 출력합니다. ex:) printText("Hello World!!",3,DEFAULT,RIGHT); //오른쪽 정렬로 우측 3칸을 비우고 현재 라인에 문자열 출력 #include #include //텍스트 출력 정렬 #define LEFT -1 #define CENTER 0 #define RIGHT 1 //기본 좌표 #define DEFAULT -1 void printText(char* buffer,int x,int y,int align){ COORD cr; CONSOLE_SCREEN_BUFFER_INFO info; int width; //콘솔 너비 int height; //콘솔 높이 GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPU.. 2011. 7. 4.
반응형