본문 바로가기

개발 업무(코딩)-개발자였을때 썼던..79

파이썬(python) 크롤링(crawling) 간단 예제(코로나 확진자수 확인) from urllib.request import urlopen from bs4 import BeautifulSoup html = urlopen("http://ncov.mohw.go.kr/bdBoardList_Real.do?brdId=1&brdGubun=11&ncvContSeq=&contSeq=&board_id=&gubun=") bsObject = BeautifulSoup(html, "html.parser") #print(bsObject) table = bsObject.find('table', {'class':'num'}) trs = table.find_all('tr') for idx, tr in enumerate(trs): if idx >= 0: tds = tr.find_all('td') ths = tr.. 2023. 1. 8.
c언어 함수포인터(fp) function pointer 간단 예제 생소한 문법으로 적혀있는 코드를 보고 무엇인지 따라 추적하다가 void (*함수포인터)()라는 것을 알았다. 간단한 테스팅 소스코드를 작성해보았고 밑에 예시는 '실전'이다. #include int add(int a, int b) { return a+b; } int mul(int a, int b) { return a*b; } int main() { int (*fp)(int, int); fp = add; printf("%d\n", fp(10,20)); // 30 출력 fp = mul; printf("%d\n", fp(10,20)); // 120 출력 } a.out https://dojang.io/mod/page/view.php?id=601 #define MAX_TR 100 typedef int (*TrFun.. 2023. 1. 8.
TR전문 자르는 방식 예제(많이 쓰는 형태여서 예시코드 작성) #include "chun.h" typedef struct { char tcphead[1]; }Head; typedef struct { Head tcphead; char a[1]; char b[1]; char count[1]; }Form, *iForm; typedef struct { char name[5]; char nick[3]; }subForm, *isubForm; void TR(char *InBuf, char *OuBuf); int main() { char *InBuf = "9132abcdefgh123456789"; char *OuBuf; TR(InBuf, OuBuf); printf("OUTPUT = %s\n", OuBuf); return 0; } void TR(char *InBuf, char *O.. 2023. 1. 8.
c와 mariadb 연결하는 방법 및 예제 3 - insert+update 한번에 Mariadb INSERT INTO csv_isstatement (codename, AsOfDate, Period, FiscalYearEnd, CurrencyId, ReportType, IsCalculated, csv_isstatement.20346) VALUES ('0C000006SP', '2000-12-31', '12M', '12', 'USD', 'A', '0', '2397284.000000') ON DUPLICATE KEY UPDATE csv_isstatement.20346 = 2397284.000000; key가 codename이고 중복된 데이터가 있다면 update를 해주는 쿼리이다. 2023. 1. 8.
c언어 리눅스(linux) 디렉토리 열기(opendir) & stat 간단 예제 #include #include #include #include #include int main() { struct dirent *item; struct stat statbuf; DIR *dp; dp = opendir("/home/tqtlhj/han/"); // 경로 설정 if (dp != NULL) { while(1) { item = readdir(dp); // item에 디렉토리를 하나씩 넣어준다. lstat(item->d_name, &statbuf); // 디렉토리인지 아닌지 체크하기 위한 stat if (item == NULL) break; if(S_ISDIR(statbuf.st_mode)) // 디렉토리 일때만 출력 printf("DIR : %s\n", item->d_name); } closed.. 2023. 1. 8.
리눅스(linux) chmod 권한설정 이라면 d는 디렉토리 앞에 rwx는 'user' 그 다음은 'group', 'others' ​ chmod 777 a.out -> r:4 w:2 x:1 이기때문에 모든 권한을 주는 것이다. 4+2+1 = 7 ​ chmod o-rwx test.txt others의 권한 rwx 박탈 ​ chmod +x *.sh -> 유저에게 실행권한 부여 ​ g를 붙이면 그룹에~ 2023. 1. 8.
c언어 리눅스(linux) 데몬프로세스(daemon) 간단 예제 #include #include #include #include #include #include #include #include // 자식프로세스 fork할 용도 #include #include int main(int argc, char *argv[]) { int pid; /* fork 생성 */ pid = fork(); printf("pid = [%d] \n", pid); /* fork 에러 발생 시 로그 남긴 후 종료 */ if(pid 0){ printf("child .. 2023. 1. 8.
c언어 리눅스(linux) UDS 간단 예제 http://www.dreamy.pe.kr/zbxe/CodeClip/119393 UDS (Unix Domain Socket) 개념 2012.02.28 13:41 조회 수 29471 댓글 0 ? 단축키 Prev이전 문서 Next다음 문서 가 + - Up Down Print ? 단축키 Prev이전 문서 Next다음 문서 가 + - Up Down Print 프로세스 끼리의 통신 UDS 내부 프로세스들 끼리의 www.dreamy.pe.kr 2023. 1. 8.
c언어 리눅스(linux) shared memory 간단 예제 shm.c에서 shared memory를 생성하고 값을 넣는다. client.c에서 shm에 있는 데이터를 출력한다. ​ shm.c #include #include #include #include typedef struct { int a; char b[10]; }Form; // shm.c int main() { int shmid; void *shared_memory = (void *)0; Form* form; /* 공유메모리 공간을 만든다. */ shmid = shmget((key_t)1234, sizeof(form), 0666|IPC_CREAT); if (shmid == -1) { perror("shmget failed : "); exit(0); } /* 공유메모리를 사용하기 위해 프로세스메모리에 붙인.. 2023. 1. 8.
c언어 리눅스(linux) fork를 이용한 프로세스 생성 예제 #include #include //#include //#include #include #include #include // 자식프로세스 fork할 용도 int main() { pid_t pid; int x = 0; pid = fork(); // 부모에게는 자식의 pid를 받아내고 자식에게는 0을 준다. -> 자식 프로세스는 부모를 복제한다. if(pid > 0) { x = 1; printf("부모 pid : %ld, x : %d, pid : %d\n", (long)getpid(), x, pid); } else if(pid == 0){ x = 2; printf("자식 pid : %ld, x : %d, pid : %d\n", (long)getpid(), x, pid); } return 0 ; } 2023. 1. 8.