Skip to content

Commit f6d4680

Browse files
committed
relocate
0 parents  commit f6d4680

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+6707
-0
lines changed

Diff for: .vscode/c_cpp_properties.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Win32",
5+
"includePath": [
6+
"${workspaceFolder}/**",
7+
"/usr/include"
8+
],
9+
"defines": [
10+
"_DEBUG",
11+
"UNICODE",
12+
"_UNICODE"
13+
],
14+
"compilerPath": "/usr/bin/g++",
15+
"cStandard": "c11",
16+
"cppStandard": "c++17",
17+
"intelliSenseMode": "gcc-x64"
18+
}
19+
],
20+
"version": 4
21+
}

Diff for: .vscode/launch.json

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "(gdb) Launch",
9+
"type": "cppdbg",
10+
"request": "launch",
11+
"program": "/home/choijaeho/projects/c/helloworld/${fileBasenameNoExtension}",
12+
"args": [""],
13+
"stopAtEntry": true,
14+
"cwd": "/home/choijaeho/projects/c/helloworld/",
15+
"environment": [],
16+
"externalConsole": true,
17+
"windows":
18+
{
19+
"MIMode": "gdb",
20+
"miDebuggerPath": "/usr/bin/gdb",
21+
"setupCommands": [
22+
{
23+
"description": "Enable pretty-printing for gdb",
24+
"text": "-enable-pretty-printing",
25+
"ignoreFailures": true
26+
}]
27+
},
28+
"pipeTransport":
29+
{
30+
"pipeCwd": "",
31+
"pipeProgram": "c:\\windows\\sysnative\\bash.exe",
32+
"pipeArgs": ["-c"],
33+
"debuggerPath": "/usr/bin/gdb"
34+
},
35+
"sourceFileMap":
36+
{
37+
"/mnt/c": "${env:systemdrive}/",
38+
// "/usr": "C:\\Users\\choij\\AppData\\Local\\Packages\\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\\LocalState\\rootfs\\usr\\"
39+
"/usr": "\\\\wsl$\\Ubuntu\\home\\choijaeho\\"
40+
}
41+
}]
42+
}

Diff for: .vscode/settings.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\wsl.exe",
3+
"files.associations": {
4+
"stdio.h": "c",
5+
"stdlib.h": "c",
6+
"DEMO2.C": "cpp"
7+
}
8+
}

Diff for: .vscode/tasks.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"version": "2.0.0",
3+
"windows": {
4+
"options": {
5+
"shell": {
6+
"executable": "bash.exe",
7+
"args": ["-c"]
8+
}
9+
}
10+
},
11+
"tasks": [
12+
{
13+
"label": "build hello world on WSL",
14+
"type": "shell",
15+
"command": "g++",
16+
"args": [
17+
"-g",
18+
"-o",
19+
"/home/choijaeho/projects/c/helloworld/${fileBasenameNoExtension}",
20+
"${fileBasename}"
21+
],
22+
"group": {
23+
"kind": "build",
24+
"isDefault": true
25+
}
26+
}
27+
]
28+
}

Diff for: 117q1-1type.c

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
도스용 type 명령어 모방 프로그램
3+
https://github.com/coreutils/coreutils/blob/master/src/cat.c
4+
*/
5+
#include <stdio.h>
6+
#include <string.h>
7+
void printfile(FILE *file, int pause);
8+
9+
int main(int argc, char **argv)
10+
{
11+
int filecount = 0;
12+
int printerror = 0;
13+
int pausepage = 0;
14+
FILE *userfile;
15+
int i;
16+
for (i = 1; i < argc; ++i)
17+
{
18+
char c = argv[i][0];
19+
// 옵션 처리
20+
if (c == '/')
21+
{
22+
// /p 옵션만 지원
23+
if (strcmp(argv[i], "/p") == 0)
24+
{
25+
pausepage++;
26+
}
27+
else
28+
{
29+
printerror++;
30+
break;
31+
}
32+
}
33+
else
34+
{
35+
// 파일명일 것임
36+
filecount++;
37+
if (filecount > 1)
38+
{
39+
printerror++;
40+
break;
41+
}
42+
else
43+
{
44+
userfile = fopen(argv[i], "r");
45+
}
46+
}
47+
}
48+
if (printerror != 0 || userfile == NULL)
49+
{
50+
if (userfile != NULL)
51+
{
52+
fclose(userfile);
53+
}
54+
else
55+
{
56+
printf("그런 파일 없음\n");
57+
}
58+
printf("사용법 : type 파일명 [/p]\n");
59+
return 1;
60+
}
61+
62+
printfile(userfile, pausepage);
63+
fclose(userfile);
64+
return 0;
65+
}
66+
67+
void printfile(FILE *file, int pause)
68+
{
69+
char parser = fgetc(file);
70+
int lfcount = 1;
71+
while (parser != EOF)
72+
{
73+
if (parser == '\n')
74+
lfcount++;
75+
printf("%c", parser);
76+
if (lfcount % 30 == 0)
77+
{
78+
// 1억 줄 넘어가면 다시 리셋
79+
if (lfcount > 100000000)
80+
{
81+
lfcount = 0;
82+
}
83+
getchar();
84+
}
85+
parser = fgetc(file);
86+
}
87+
}

Diff for: 117q1maketxt.c

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
사용자로 부터 경로를 입력 받아서 그 곳에 파일을 생성하고 a 를 입력해놓는 프로그램을 만들어보세요
3+
https://modoocode.com/117
4+
*/
5+
#include <stdio.h>
6+
#include <string.h>
7+
#include <stdlib.h>
8+
9+
#define LOREMIPSUM "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n"
10+
11+
int main()
12+
{
13+
FILE *userfile;
14+
char *userpath;
15+
16+
printf("파일명을 포함한 경로를 입력하시요여.:");
17+
scanf("%s", userpath);
18+
19+
userfile = fopen(userpath, "w");
20+
21+
if (userfile == NULL)
22+
{
23+
printf("못만듬. 에러!\n");
24+
return 1;
25+
}
26+
27+
fputs(LOREMIPSUM, userfile);
28+
29+
fclose(userfile);
30+
31+
return 0;
32+
}

Diff for: 117q2findinfile.c

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
a.txt 에 어떠한 긴 글이 들어 있는데, 이 글을 입력 받아서 특정한 문자열을 검색하는 프로그램을 만들어보세요
3+
*/
4+
5+
#include <stdio.h>
6+
void scanTheFile(char *needle, FILE *haystack);
7+
8+
int main(int argc, char **argv)
9+
{
10+
FILE *theFile;
11+
char needle[120];
12+
if (argc != 2)
13+
{
14+
printf("사용법: %s 파일명\n", argv[0]);
15+
return 1;
16+
}
17+
theFile = fopen(argv[1], "r");
18+
if (theFile == NULL)
19+
{
20+
printf("file not found\n");
21+
return 1;
22+
}
23+
24+
printf("찾으려는 문자열을 입력하시요: ");
25+
// char needle[120] 즉 배열이므로 바로 scanf 때린다
26+
// 바로 char *needle 하고 scanf 때리면 안되는 이유
27+
// https://stackoverflow.com/questions/4900394/char-p-and-scanf
28+
scanf("%s", needle);
29+
printf("입력받은 값: %s\n", needle);
30+
31+
scanTheFile(needle, theFile);
32+
33+
fclose(theFile);
34+
35+
return 0;
36+
}
37+
38+
void scanTheFile(char *needle, FILE *haystack)
39+
{
40+
int i, index = 1, found;
41+
char parser= fgetc(haystack);
42+
while ((parser ) != EOF)
43+
{
44+
if (parser == needle[0])
45+
{
46+
found = 1;
47+
for (i = 1; i < sizeof(needle) && needle[i] != '\0'; ++i)
48+
{
49+
parser = fgetc(haystack);
50+
// printf("\n여기까지는 실행됨 %d %c %c\n", index, parser, needle[i]);
51+
if (parser != needle[i])
52+
{
53+
found = 0;
54+
break;
55+
}
56+
}
57+
if (found == 0)
58+
{
59+
found = 1;
60+
}
61+
else
62+
{
63+
printf("i:%d ", index-1);
64+
}
65+
fseek(haystack, index, SEEK_SET);
66+
}
67+
index++;
68+
parser = fgetc(haystack);
69+
}
70+
printf("\n탐색 종료\n");
71+
}

Diff for: 117q3strreveresout.c

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
a.txt 에 문자열을 입력 받아서 b.txt 에 그 문자열을 역으로 출력하는 프로그램을 만들어보세요
3+
*/
4+
#include <stdio.h>
5+
int getFileSize(FILE *file);
6+
void rcopyFileOP(FILE *dst, FILE *src);
7+
8+
int main(int argc, char **argv)
9+
{
10+
if (argc != 3)
11+
{
12+
printf("사용법 : %s source_filename dest_filename\n", argv[0]);
13+
return 1;
14+
}
15+
FILE *dstFile = fopen(argv[2], "w+");
16+
FILE *srcFile = fopen(argv[1], "r");
17+
if (dstFile == NULL || srcFile == NULL)
18+
{
19+
printf("진행 못함\n");
20+
return 1;
21+
}
22+
23+
rcopyFileOP(dstFile, srcFile);
24+
25+
printf("끝.\n");
26+
fclose(dstFile);
27+
fclose(srcFile);
28+
return 0;
29+
}
30+
31+
void rcopyFileOP(FILE *dst, FILE *src)
32+
{
33+
int i = 1;
34+
int i2 = 1;
35+
int j = ++i;
36+
int j2 = i2++;
37+
printf("j:%d j2:%d\n",j,j2);
38+
39+
char p;
40+
int srcSize = getFileSize(src);
41+
int index = 0;
42+
while (srcSize-- > 0)
43+
{
44+
fseek(src, srcSize, SEEK_SET);
45+
p = fgetc(src);
46+
printf(" %d:%d",srcSize,p);
47+
// index++;
48+
fputc(p, dst);
49+
}
50+
// fputc(0xA, dst); // ascii 0xA == line feed;
51+
}
52+
53+
int getFileSize(FILE *file)
54+
{
55+
int counter = 0;
56+
char p;
57+
while ((p = fgetc(file)) != EOF)
58+
{
59+
counter++;
60+
printf(" %d:%d",counter, p);
61+
}
62+
// 가장 마지막에 LF(아스키 코드 10)이 붙음
63+
printf("길이:%d\n",counter);
64+
return counter;
65+
}

Diff for: 1darraypointer.c

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <stdio.h>
2+
3+
int main()
4+
{
5+
int arr[10] = {60, 58, 77, 55, 79, 46, 82, 16, 10, 49};
6+
int *parr;
7+
int sum = 0;
8+
9+
parr = arr;
10+
11+
printf("니 시험 점수\n");
12+
while (parr - arr <= 9)
13+
{
14+
printf(" %d ", *parr);
15+
sum += *parr;
16+
parr++;
17+
}
18+
printf("\n");
19+
printf("니 시험 점수 평균 : %3.2f\n", sum * 0.1);
20+
21+
return 0;
22+
}

0 commit comments

Comments
 (0)