호스트 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));                         }                 }         }         WSACleanup(); }

파일 다운로드 하기

-인자로 전달받은 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; }

시스템 드라이브 목록 얻기

-현재 시스템의 드라이브 목록을 얻습니다. #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

운영체제 정보 얻기

-현재 실행중인 운영체제의 정보를 얻습니다. #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); }

콘솔 텍스트 출력하기

-콘솔의 원하는 위치에 텍스트를 출력합니다. 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; //콘솔 높이 … 더 읽기

콘솔 창 숨기기

-현재 실행중인 콘솔 창을 보이지 않게 숨긴다. #include #define BUFSIZE 512 int main(){         HWND hwnd;         char title[BUFSIZE]=”My Title”;         SetConsoleTitle(title); //타이틀 설정         hwnd=FindWindow(NULL,title); //타이틀에 해당하는 윈도우 핸들 얻기         ShowWindow(hwnd,SW_HIDE); //숨김 옵션 설정           return 0; }

파일 관련 API

GetCurrentDirectory -현재 실행중인 파일의 경로를 리턴한다. GetModuleFileName -현재 실행중인 파일의 경로와 파일명을 리턴한다.(2번째 인자 이용) SetFilePointer(hfile,IDistanceToMove,IDistanceToMoveHigh,dwMoveMethod) -파일 포인터의 위치를 설정한다. ▶hfile : 파일 핸들러 ▶IDistanceToMove : 주소 지정 ▶IDistanceToMoveHigh : 64bit 주소 지정에 사용 ▶dwMoveMethod : 움직일 방향 (시작 지점) -FILE_BEGIN : 파일 시작 지점 (0) -FILE_CURRENT : 현재 포인터 위치 (1) -FILE_END : 파일 … 더 읽기

C에서 입력 버퍼를 비울 때 피해야할 방법

[강좌] C에서 입력 버퍼를 비울 때 피해야할 방법 (C언어를 배우자) |작성자 네가티브 #include  int main(int argc, char *argv[]) {  int d;  while(1)  {   scanf(“%d”, &d);   printf(“%d\n”, d);  }  return 0; }  실행해보시면 숫자를 입력할 시 그 숫자가 화면에 출력되는 형태로  무한 반복됨을 알 수 있습니다. 그런데, 여기에 문자를 입력하면 무한 루프에  빠지게 됩니다.  이걸 방지하고자 … 더 읽기

readn() & writen() 코드, unpipc.h 파일

unpipc.h 다운로드 unpipc.h 를 include 하고 사용한다. 일반 read()&write() 함수와 사용법은 같다.  readn ssize_t readn(int fd, void *vptr, size_t n) {  size_t nleft;  ssize_t nread;  char *ptr;  ptr = vptr;  nleft = n;  while (nleft > 0) {   if ( (nread = read(fd, ptr, nleft)) < 0) {    if (errno == EINTR)     nread = 0;  /* ... 더 읽기
바로가기