diff options
author | David Timber <dxdt@dev.snart.me> | 2024-11-12 05:57:44 +0100 |
---|---|---|
committer | David Timber <dxdt@dev.snart.me> | 2024-11-12 05:57:44 +0100 |
commit | 5fc6f750a207a9918c33f050409feae9f3dd3166 (patch) | |
tree | cf2c18b9ebb5c7c3cfefb1271696f97eda20eaef | |
parent | be3b15d64e9f6b8c2489b296c7f4b63487aa5564 (diff) |
Dump some files from personal directory
-rw-r--r-- | .vscode/c_cpp_properties.json | 16 | ||||
-rw-r--r-- | Makefile | 12 | ||||
-rw-r--r-- | qna/gggg123.c | 29 | ||||
-rw-r--r-- | qna/subproc.c | 4 | ||||
-rw-r--r-- | qna/아픈뜸부기_a.c | 34 | ||||
-rw-r--r-- | qna/아픈뜸부기_b.c | 37 | ||||
-rw-r--r-- | snippets/clipblink.c | 104 |
7 files changed, 236 insertions, 0 deletions
diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..f6f2d94 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,16 @@ +{ + "configurations": [ + { + "name": "Linux", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [], + "cStandard": "c17", + "cppStandard": "c++17", + "intelliSenseMode": "linux-clang-x64", + "compilerPath": "/usr/bin/gcc" + } + ], + "version": 4 +}
\ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5e6c997 --- /dev/null +++ b/Makefile @@ -0,0 +1,12 @@ +CC_D = gcc -Wall -Wextra -pedantic -g -O0 +CC_R = gcc -Wall -Wextra -pedantic -g -O2 +CC ?= CC_D + +OBJ = + +all: + echo "Make what, mate? (no default target)" >&2 + exit 2 + +clean: + rm -f $(OBJ) diff --git a/qna/gggg123.c b/qna/gggg123.c new file mode 100644 index 0000000..b776e4e --- /dev/null +++ b/qna/gggg123.c @@ -0,0 +1,29 @@ +#include <stdio.h> + +int main() + +{ + int x, y, z; //정수 변수 정의 + scanf("%d %d %d", &x, &y, &z); //x, y, z 입력 + int xh, yh, zh; //각 변수의 백의 자리수에 대한 변수 정의 + xh = x/100; //x 백의 자리수 + yh = y/100; //y 백의 자리수 + zh = z/100; //z 백의 자리수 + + char ch[3]; + + // 각 수의 백의 자리수가 모두 같으면 T + ch[0] = 'T' * (xh == yh && yh == zh); + // 두 수의 백의 자리수만 같으면 D + ch[1] = + 'D' * + (ch[0] == 0) * /* 근데 모두 같으면 출력하면 안 됨 */ + (xh == yh || yh == zh || zh == xh); + // 백의 자리수가 모두 다르면 S + ch[2] = 'S' * (xh != yh && yh != zh && zh != xh); + + //T,D,S를 입력받는 변수 ch를 정의하고 각 조건에 맞는 문자를 대입(조건이 거짓이면 0을 곱해서 무효처리) + printf("%c%c%c\n", ch[0], ch[1], ch[2]); //ch 출력 + + return 0; +} diff --git a/qna/subproc.c b/qna/subproc.c new file mode 100644 index 0000000..160492d --- /dev/null +++ b/qna/subproc.c @@ -0,0 +1,4 @@ +#include <stdio.h> + + +int main
\ No newline at end of file diff --git a/qna/아픈뜸부기_a.c b/qna/아픈뜸부기_a.c new file mode 100644 index 0000000..4022b8d --- /dev/null +++ b/qna/아픈뜸부기_a.c @@ -0,0 +1,34 @@ +#define _CRT_SECURE_NO_WARNING // https://blog.hcmc.studio/73 +#include <stdio.h> + +int main (void) { + int n, num; + int sum = 0; + int a, b, c, d; + + printf("4자리 정수를 입력하시오: "); + scanf("%d", &n); + num = n; + printf("\n"); + + a = n % 1000 % 100 % 10; + printf("\tn = %4d --> 일의 자리값 --> %d \n", n, a); + n = n % 1000; + + b = n / 10 % 10; + printf("\tn = %4d --> 십의 자리값 --> %d \n", n, b); + n = n / 100; + + c = n % 100 % 10; + printf("\tn = %4d --> 백의 자리값 --> %d \n", n, c); + n = n % 10; + + d = n % 10; + printf("\tn = %4d --> 천의 자리값 --> %d \n", n, d); + n = n % 10; + + sum = d + c + b + a; + printf("n = %4d --> %d + %d + %d + %d = %d \n", num, a, b, c, d, sum); + + return 0; +} diff --git a/qna/아픈뜸부기_b.c b/qna/아픈뜸부기_b.c new file mode 100644 index 0000000..808100a --- /dev/null +++ b/qna/아픈뜸부기_b.c @@ -0,0 +1,37 @@ +#define _CRT_SECURE_NO_WARNING // https://blog.hcmc.studio/73 +#include <stdio.h> + +int main (void) { + static const char *STR_ARR[] = { + "일", + "십", + "백", + "천", + }; + static const size_t STR_ARR_LEN = sizeof(STR_ARR) / sizeof(const char*); + + int n, num; + int sum = 0; + int h[STR_ARR_LEN]; + + printf("4자리 정수를 입력하시오: "); + scanf("%d", &n); + num = n; + printf("\n"); + + for (size_t i = 0; i < STR_ARR_LEN; i += 1) { + h[i] = n % 10; + sum += h[i]; + + printf("\tn = %4d --> %s의 자리값 --> %d \n", n, STR_ARR[i], h[i]); + n /= 10; + } + + printf("\nn = %4d --> ", num); + for (size_t i = 0; i < STR_ARR_LEN; i += 1) { + printf("%d %c ", h[i], i + 1 == STR_ARR_LEN ? '=' : '+'); + } + printf("%d\n", sum); + + return 0; +} diff --git a/snippets/clipblink.c b/snippets/clipblink.c new file mode 100644 index 0000000..d84ca75 --- /dev/null +++ b/snippets/clipblink.c @@ -0,0 +1,104 @@ +// https://github.com/cdown/clipnotify + +#define _DEFAULT_SOURCE +#include <X11/Xatom.h> +#include <X11/Xlib.h> +#include <X11/extensions/Xfixes.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +static enum selections { + NONE = 0, + SELECTION_CLIPBOARD = (1 << 0), + SELECTION_PRIMARY = (1 << 1), + SELECTION_SECONDARY = (1 << 2) +} selections = NONE; + +static int loop; + +int main(int argc, char *argv[]) { + static const char *usage = + "%s: Notify by exiting on clipboard events.\n\n" + " -l Instead of exiting, print a newline when a new selection is available.\n" + " -s The selection to use. Available selections:\n" + " clipboard, primary, secondary\n" + " The default is to monitor clipboard and primary.\n"; + Display *disp; + Window root; + Atom clip; + XEvent evt; + int opt; + + while ((opt = getopt(argc, argv, "hs:l")) != -1) { + switch (opt) { + case 'h': + printf(usage, argv[0]); + return EXIT_SUCCESS; + case 'l': + loop = 1; + break; + case 's': { + char *token = strtok(optarg, ","); + while (token != NULL) { + if (strcmp(token, "clipboard") == 0) { + selections |= SELECTION_CLIPBOARD; + } else if (strcmp(token, "primary") == 0) { + selections |= SELECTION_PRIMARY; + } else if (strcmp(token, "secondary") == 0) { + selections |= SELECTION_SECONDARY; + } else { + fprintf(stderr, "Unknown selection '%s'\n", token); + return EXIT_FAILURE; + } + token = strtok(NULL, ","); + } + break; + } + default: + fprintf(stderr, usage, argv[0]); + return EXIT_FAILURE; + } + } + + disp = XOpenDisplay(NULL); + if (!disp) { + fprintf(stderr, "Can't open X display\n"); + return EXIT_FAILURE; + } + + root = DefaultRootWindow(disp); + + clip = XInternAtom(disp, "CLIPBOARD", False); + + /* <= 1.0.2 backwards compatibility */ + if (!selections) + selections = SELECTION_CLIPBOARD | SELECTION_PRIMARY; + + if (selections & SELECTION_CLIPBOARD) + XFixesSelectSelectionInput(disp, root, clip, + XFixesSetSelectionOwnerNotifyMask); + if (selections & SELECTION_PRIMARY) + XFixesSelectSelectionInput(disp, root, XA_PRIMARY, + XFixesSetSelectionOwnerNotifyMask); + if (selections & SELECTION_SECONDARY) + XFixesSelectSelectionInput(disp, root, XA_SECONDARY, + XFixesSetSelectionOwnerNotifyMask); + + if (loop) { + (void)setvbuf(stdout, NULL, _IONBF, 0); + do { + XNextEvent(disp, &evt); + + for (unsigned int i = 0; i < 2; i += 1) { + printf("%c", 0); + fflush(stdout); + usleep(50000); + } + } while (1); + } else { + XNextEvent(disp, &evt); + } + XCloseDisplay(disp); +} |