목록CODE (16)
SPRING :: NOTE
출처 : 윤성우 열혈 TCP/IP 소켓 프로그래밍 서버작성 : hello_server_win.c #include #include #include void ErrorHandling(char* message); int main(int argc, char* argv[]) { WSADATA wsaData; SOCKET hServSock, hClntSock; SOCKADDR_IN servAddr, clntAddr; int szClntAddr; char message[] = "hello world!"; if(argc!=2) { printf("usage : %d \n", argv[0]); exit(1); } // 소켓 라이브러리를 초기화 if(WSAStartup(MAKEWORD(2,2), &wsaData) != 0)..
예제 1. 포인터의 개념 #include int main() { int i = 10, j = 20, *a; // 정수 변수 i, j, 및 정수 포인터 변수 a선언 a = &i; // 정수 포인터 변수 a에 i의 주소 저장 printf("%p, %p\n", &i, &a); // 정수 변수 i의 주소 및 a의 주소 출력 printf("%d\n\n", *a); // 정수 포인터 a가 가리키는 곳의 데이터 출력, // 즉, 정수 포인터 a는 i의 주소를 가지고 i의 값을 출력한다. a = &j; // 정수 포인터 변수 a에 j의 주소 저장 printf("%p, %p\n", &j, &a); // 정수 변수 i의 주소 및 a의 주소 출력 printf("%d\n", *a); // 정수 포인터 a가 가리키는 곳의 데이..
gotoxy를 이용하여 해당 단어를 배치하고 이동과 동시에 전 블럭에 있던 단어를 공백으로 바꿔준다, 결과는 >문자가 오른쪽으로 이동하는걸 확인할 수 있다. #include #include #include void gotoxy(int x,int y) { COORD pos={x,y}; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos); } void main() { int i; for(i = 0; i 과 공백을 번갈아가며 출력한다. 실행해 보면 >문자가 최초 화면 왼쪽에 나타났다가 오른쪽 끝으로 한칸씩 이동할 것이다. 문자 하나만 움직이지만 이것도 일종의 애니메이션이라고 할 수 있다. 어떻게 해서 >이 움직이는지 분석해 보자. 루프를 돌 때 제어..
#define _CRT_SECURE_NO_DEPRECATE #include "stdio.h" #include "windows.h" #include "stdafx.h" typedef struct SumInfo { int a, b, s; }SUMINFO, *PSUMINFO; void Sum(void* p); void main() { char temp[1024]; printf("sum\n"); DWORD dwThreadld; SUMINFO si = { 1, 100, 0 }; HANDLE h = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Sum, &si, NULL, &dwThreadld); CloseHandle(h); scanf_s(temp); } void Sum(void..
#define _CRT_SECURE_NO_DEPRECATE #include "windows.h" typedef struct SumInfo { int a, b, s; }SUMINFO, *PSUMINFO; DWORD WINAPI Sum(void* p); HANDLE g_hConsoleOut; void writeString(LPCTSTR lpszFormat, ...) { char str[1024] = { 0 }; va_list argList; DWORD dwNumberOfBytesWritten; va_start(argList, lpszFormat); wvsprintf(str, lpszFormat, argList); va_end(argList); WriteFile(g_hConsoleOut, str, lstrle..
#include #include #include #include typedef struct SumInfo { int a, b, s; }SUMINFO, *PSUMINFO; unsigned _stdcall Sum(void* p); void WriteString(const char* lpszFormat, ...) { char str[1024] = { 0 }; va_list argList; va_start(argList, lpszFormat); vprintf(lpszFormat, argList); // 런타임 함수 va_end(argList); } void main() { char temp[1024]; unsigned dwThreadId; printf("*** 예제 C Runtime Library를 이용한 스레..
16진수 값을 받아와 8bit 2진수로 변환해서 바이너리 파일로 저장해주는 프로그램 /* Libraries */ #include #include #include #pragma warning(disable : 4996) #define _CRT_SECURE_NO_DEPRECATE void main() { int j; char binaryNum[10], *pointer; char hexNum[10]; FILE *f; while (true) { gets(hexNum); /* From Hex convert to decimal */ j = strtol(hexNum, &pointer, 16); /* From Decimal convert to Binary */ itoa(j, binaryNum, 2); printf("H..
아주 단순한 바이너리 파일 변환기 temp에 저장해서 한방에 바이너리로 변환해준다. /* Libraries */ #include #include #include #include #pragma warning(disable : 4996) #define _CRT_SECURE_NO_DEPRECATE void main() { FILE *f; char temp[] = { 0x00, 0x00, 0x02, 0xc8, 0x00 }; f = fopen("bin.bin", "wb"); fwrite(temp, 1, 5, f); fclose(f); }