Skip to content

Commit 26c2e69

Browse files
authoredSep 26, 2017
last version
1 parent 5c11ff0 commit 26c2e69

File tree

3 files changed

+211
-32
lines changed

3 files changed

+211
-32
lines changed
 

‎HomeWork2.vcxproj

+150
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<ItemGroup>
22+
<ClCompile Include="Homework2.c" />
23+
</ItemGroup>
24+
<PropertyGroup Label="Globals">
25+
<ProjectGuid>{2C7D00BC-FECA-431E-B291-F380C3ADE48B}</ProjectGuid>
26+
<Keyword>Win32Proj</Keyword>
27+
<RootNamespace>HomeWork2</RootNamespace>
28+
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
29+
</PropertyGroup>
30+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
31+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
32+
<ConfigurationType>Application</ConfigurationType>
33+
<UseDebugLibraries>true</UseDebugLibraries>
34+
<PlatformToolset>v140</PlatformToolset>
35+
<CharacterSet>Unicode</CharacterSet>
36+
</PropertyGroup>
37+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
38+
<ConfigurationType>Application</ConfigurationType>
39+
<UseDebugLibraries>false</UseDebugLibraries>
40+
<PlatformToolset>v140</PlatformToolset>
41+
<WholeProgramOptimization>true</WholeProgramOptimization>
42+
<CharacterSet>Unicode</CharacterSet>
43+
</PropertyGroup>
44+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
45+
<ConfigurationType>Application</ConfigurationType>
46+
<UseDebugLibraries>true</UseDebugLibraries>
47+
<PlatformToolset>v140</PlatformToolset>
48+
<CharacterSet>Unicode</CharacterSet>
49+
</PropertyGroup>
50+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
51+
<ConfigurationType>Application</ConfigurationType>
52+
<UseDebugLibraries>false</UseDebugLibraries>
53+
<PlatformToolset>v140</PlatformToolset>
54+
<WholeProgramOptimization>true</WholeProgramOptimization>
55+
<CharacterSet>Unicode</CharacterSet>
56+
</PropertyGroup>
57+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
58+
<ImportGroup Label="ExtensionSettings">
59+
</ImportGroup>
60+
<ImportGroup Label="Shared">
61+
</ImportGroup>
62+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
63+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
64+
</ImportGroup>
65+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
66+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
67+
</ImportGroup>
68+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
69+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
70+
</ImportGroup>
71+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
72+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
73+
</ImportGroup>
74+
<PropertyGroup Label="UserMacros" />
75+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
76+
<LinkIncremental>true</LinkIncremental>
77+
</PropertyGroup>
78+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
79+
<LinkIncremental>true</LinkIncremental>
80+
</PropertyGroup>
81+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
82+
<LinkIncremental>false</LinkIncremental>
83+
</PropertyGroup>
84+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
85+
<LinkIncremental>false</LinkIncremental>
86+
</PropertyGroup>
87+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
88+
<ClCompile>
89+
<PrecompiledHeader>
90+
</PrecompiledHeader>
91+
<WarningLevel>Level3</WarningLevel>
92+
<Optimization>Disabled</Optimization>
93+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
94+
</ClCompile>
95+
<Link>
96+
<SubSystem>Console</SubSystem>
97+
<GenerateDebugInformation>true</GenerateDebugInformation>
98+
</Link>
99+
</ItemDefinitionGroup>
100+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
101+
<ClCompile>
102+
<PrecompiledHeader>
103+
</PrecompiledHeader>
104+
<WarningLevel>Level3</WarningLevel>
105+
<Optimization>Disabled</Optimization>
106+
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
107+
</ClCompile>
108+
<Link>
109+
<SubSystem>Console</SubSystem>
110+
<GenerateDebugInformation>true</GenerateDebugInformation>
111+
</Link>
112+
</ItemDefinitionGroup>
113+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
114+
<ClCompile>
115+
<WarningLevel>Level3</WarningLevel>
116+
<PrecompiledHeader>
117+
</PrecompiledHeader>
118+
<Optimization>MaxSpeed</Optimization>
119+
<FunctionLevelLinking>true</FunctionLevelLinking>
120+
<IntrinsicFunctions>true</IntrinsicFunctions>
121+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
122+
</ClCompile>
123+
<Link>
124+
<SubSystem>Console</SubSystem>
125+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
126+
<OptimizeReferences>true</OptimizeReferences>
127+
<GenerateDebugInformation>true</GenerateDebugInformation>
128+
</Link>
129+
</ItemDefinitionGroup>
130+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
131+
<ClCompile>
132+
<WarningLevel>Level3</WarningLevel>
133+
<PrecompiledHeader>
134+
</PrecompiledHeader>
135+
<Optimization>MaxSpeed</Optimization>
136+
<FunctionLevelLinking>true</FunctionLevelLinking>
137+
<IntrinsicFunctions>true</IntrinsicFunctions>
138+
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
139+
</ClCompile>
140+
<Link>
141+
<SubSystem>Console</SubSystem>
142+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
143+
<OptimizeReferences>true</OptimizeReferences>
144+
<GenerateDebugInformation>true</GenerateDebugInformation>
145+
</Link>
146+
</ItemDefinitionGroup>
147+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
148+
<ImportGroup Label="ExtensionTargets">
149+
</ImportGroup>
150+
</Project>

‎HomeWork2.vcxproj.filters

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="Source Files">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="Header Files">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="Resource Files">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ClCompile Include="Homework2.c">
19+
<Filter>Source Files</Filter>
20+
</ClCompile>
21+
</ItemGroup>
22+
</Project>

‎Homework2.c

+39-32
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
char * reverse(char * str1);
55
char * encrypt(char * str1, int n);
66
char * rotate(char * str1, int n);
7+
int CheckRange(char str1, int n);
78

89
int main(void)
910
{
@@ -17,27 +18,14 @@ int main(void)
1718
printf("입력 종료를 원하면 새로운 행에서 ctrl+z 입력\n");
1819
printf("Enter String(more than 20 chars): ");
1920

20-
while (gets(Sentence))
21-
{
22-
while (Sentence[count])
23-
count++;
24-
25-
for (int i = 0; i < count; i++)
26-
{
27-
if (Sentence[i] < 65 || Sentence[i] > 122 || (Sentence[i] > 90 && Sentence[i] < 97))
28-
{
29-
printf("문자열만 입력해주세요\n");
30-
break;
31-
}
32-
}
33-
}
21+
gets(Sentence);
3422

35-
printf("얼마나 Encryt하실 건가요?: ");
23+
printf("얼마나 Encrypt하실 건가요?: ");
3624
scanf("%d", &Encrypt_num);
3725
printf("얼마나 rotate 하실 건가요?: ");
38-
scanf("%d", &Rotate_num); // 함수 내에서 rotate_num만큼 for문을 돌린다.
26+
scanf("%d", &Rotate_num);
3927

40-
printf("String Entered: \t");
28+
printf("\nString Entered: \t");
4129
puts(Sentence);
4230

4331
printf("Reversed: \t\t");
@@ -48,17 +36,16 @@ int main(void)
4836
printf("Encrypted: \t\t");
4937
encrypt(Sentence, Encrypt_num);
5038
puts(Sentence);
51-
encrypt(Sentence, -Encrypt_num);//원래대로 배열 돌리기
39+
encrypt(Sentence, -Encrypt_num); //원래대로 배열 돌리기
5240

5341
printf("Rotated: \t\t");
5442
rotate(Sentence, Rotate_num);
5543
puts(Sentence);
44+
printf("\n");
5645

5746
return 0;
58-
5947
}
6048

61-
6249
char * reverse(char * str1)
6350
{
6451
char temp = 0;
@@ -77,27 +64,49 @@ char * reverse(char * str1)
7764
return str1;
7865
}
7966

80-
8167
char * encrypt(char * str1, int n)
8268
{
8369
int count = 0;
8470

8571
while (*(str1 + count))
8672
count++;
87-
//65~90 대문자, 97~122 소문자
73+
8874
for (int i = 0; i < count; i++)
8975
{
90-
if (*(str1 + i) >= 65 && *(str1 + i) <= 90)
91-
*(str1 + i) += n;
92-
else if (*(str1 + i) >= 97 && *(str1 + i) <= 122)
93-
*(str1 + i) += n;
94-
else
95-
break;
96-
}
76+
int check1 = CheckRange(str1[i], 0);
77+
int check2;
78+
79+
if (n > 26 || n < -26) //연산을 하면 알파벳 범위를 벗어나는 값들의 범위
80+
n %= 26;
9781

82+
if (check1) // 알파벳만을 입력했을 때를 가정한다.
83+
{
84+
85+
check2 = CheckRange(str1[i], n);
86+
if (check1 == check2)
87+
*(str1 + i) += n;
88+
else
89+
{
90+
if (n > 0)
91+
*(str1 + i) = *(str1 + i) + n - 26;
92+
else
93+
*(str1 + i) = *(str1 + i) + n + 26;
94+
}
95+
}
96+
}
9897
return str1;
9998
}
10099

100+
int CheckRange(char str1, int n) // 알파벳이 아닌 경우에만 0을 반환한다.
101+
{
102+
if (str1 + n >= 65 && str1 + n <= 90)
103+
return 1;
104+
else if (str1 + n >= 97 && str1 + n <= 122)
105+
return 2;
106+
else
107+
return 0;
108+
}
109+
101110
char * rotate(char * str1, int n)
102111
{
103112
int count = 0;
@@ -118,6 +127,4 @@ char * rotate(char * str1, int n)
118127
}
119128

120129
return str1;
121-
}
122-
123-
130+
}

0 commit comments

Comments
 (0)
Please sign in to comment.