Skip to content

Commit 207ef14

Browse files
committed
Add LICENSE, README.md, and use PCH
1 parent 929f545 commit 207ef14

File tree

9 files changed

+111
-22
lines changed

9 files changed

+111
-22
lines changed

C-Programming-Examples.vcxproj

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,29 @@
7878
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
7979
</ImportGroup>
8080
<PropertyGroup Label="UserMacros" />
81+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
82+
<IncludePath>$(ProjectDir);$(IncludePath)</IncludePath>
83+
</PropertyGroup>
84+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">
85+
<IncludePath>$(ProjectDir);$(IncludePath)</IncludePath>
86+
</PropertyGroup>
87+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
88+
<IncludePath>$(ProjectDir);$(IncludePath)</IncludePath>
89+
</PropertyGroup>
90+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
91+
<IncludePath>$(ProjectDir);$(IncludePath)</IncludePath>
92+
</PropertyGroup>
93+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
94+
<IncludePath>$(ProjectDir);$(IncludePath)</IncludePath>
95+
</PropertyGroup>
96+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
97+
<IncludePath>$(ProjectDir);$(IncludePath)</IncludePath>
98+
</PropertyGroup>
8199
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
82100
<ClCompile>
83101
<SDLCheck>true</SDLCheck>
84102
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
103+
<PrecompiledHeader>Use</PrecompiledHeader>
85104
</ClCompile>
86105
<Link>
87106
<SubSystem>Console</SubSystem>
@@ -93,6 +112,7 @@
93112
<IntrinsicFunctions>true</IntrinsicFunctions>
94113
<SDLCheck>true</SDLCheck>
95114
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
115+
<PrecompiledHeader>Use</PrecompiledHeader>
96116
</ClCompile>
97117
<Link>
98118
<SubSystem>Console</SubSystem>
@@ -102,6 +122,7 @@
102122
<ClCompile>
103123
<SDLCheck>true</SDLCheck>
104124
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
125+
<PrecompiledHeader>Use</PrecompiledHeader>
105126
</ClCompile>
106127
<Link>
107128
<SubSystem>Console</SubSystem>
@@ -111,6 +132,7 @@
111132
<ClCompile>
112133
<SDLCheck>true</SDLCheck>
113134
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
135+
<PrecompiledHeader>Use</PrecompiledHeader>
114136
</ClCompile>
115137
<Link>
116138
<SubSystem>Console</SubSystem>
@@ -122,6 +144,7 @@
122144
<IntrinsicFunctions>true</IntrinsicFunctions>
123145
<SDLCheck>true</SDLCheck>
124146
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
147+
<PrecompiledHeader>Use</PrecompiledHeader>
125148
</ClCompile>
126149
<Link>
127150
<SubSystem>Console</SubSystem>
@@ -133,19 +156,27 @@
133156
<IntrinsicFunctions>true</IntrinsicFunctions>
134157
<SDLCheck>true</SDLCheck>
135158
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
159+
<PrecompiledHeader>Use</PrecompiledHeader>
136160
</ClCompile>
137161
<Link>
138162
<SubSystem>Console</SubSystem>
139163
</Link>
140164
</ItemDefinitionGroup>
141165
<ItemGroup>
142-
<ClInclude Include="Public.h" />
166+
<ClInclude Include="pch.h" />
143167
</ItemGroup>
144168
<ItemGroup>
145-
<ClCompile Include="DataStructure\LinkedListReverse.c" />
169+
<ClCompile Include="DataStructure\LinkedList\Reverse.c" />
146170
<ClCompile Include="Main.c" />
147171
<ClCompile Include="Print\MultiplicationTable.c" />
148-
<ClCompile Include="Public.c" />
172+
<ClCompile Include="pch.c">
173+
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
174+
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
175+
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">Create</PrecompiledHeader>
176+
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">Create</PrecompiledHeader>
177+
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
178+
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
179+
</ClCompile>
149180
</ItemGroup>
150181
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
151182
<ImportGroup Label="ExtensionTargets">
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<ItemGroup>
4-
<ClInclude Include="Public.h" />
4+
<ClInclude Include="pch.h" />
55
</ItemGroup>
66
<ItemGroup>
77
<Filter Include="Print">
@@ -10,15 +10,18 @@
1010
<Filter Include="DataStructure">
1111
<UniqueIdentifier>{599904f4-287c-4a67-bd20-b9d7eca41625}</UniqueIdentifier>
1212
</Filter>
13+
<Filter Include="DataStructure\LinkedList">
14+
<UniqueIdentifier>{25a4f240-fb6b-40f4-bc4d-49fd6a2936ac}</UniqueIdentifier>
15+
</Filter>
1316
</ItemGroup>
1417
<ItemGroup>
1518
<ClCompile Include="Print\MultiplicationTable.c">
1619
<Filter>Print</Filter>
1720
</ClCompile>
18-
<ClCompile Include="DataStructure\LinkedListReverse.c">
19-
<Filter>DataStructure</Filter>
20-
</ClCompile>
21-
<ClCompile Include="Public.c" />
21+
<ClCompile Include="pch.c" />
2222
<ClCompile Include="Main.c" />
23+
<ClCompile Include="DataStructure\LinkedList\Reverse.c">
24+
<Filter>DataStructure\LinkedList</Filter>
25+
</ClCompile>
2326
</ItemGroup>
2427
</Project>

DataStructure/LinkedListReverse.c renamed to DataStructure/LinkedList/Reverse.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#include "../Public.h"
1+
#include "pch.h"
22

33
static
44
PLINKED_LIST
5-
LinkedListReverse(
5+
Reverse(
66
_In_ PLINKED_LIST LinkedList)
77
{
88
PLINKED_LIST pPrev, pCurrent, pTemp;
@@ -30,13 +30,13 @@ LinkedListReverse(
3030

3131
_Function_class_(FN_EXAMPLE_PROC)
3232
bool
33-
DataStructure_LinkedListReverse(void)
33+
DataStructure_LinkedList_Reverse(void)
3434
{
3535
PLINKED_LIST ReverseLinkedList;
3636

3737
/* Print LinkedListA and reversed result */
3838
PrintLinkedList(LinkedListA);
39-
ReverseLinkedList = LinkedListReverse(LinkedListA);
39+
ReverseLinkedList = Reverse(LinkedListA);
4040
PrintLinkedList(ReverseLinkedList);
4141

4242
/* Verify result */
@@ -49,12 +49,12 @@ DataStructure_LinkedListReverse(void)
4949
}
5050

5151
/* Restore LinkedListA and return success */
52-
LinkedListA = LinkedListReverse(ReverseLinkedList);
52+
LinkedListA = Reverse(ReverseLinkedList);
5353

5454
/* Test LinkedListB, which has only one node */
5555

5656
PrintLinkedList(LinkedListB);
57-
ReverseLinkedList = LinkedListReverse(LinkedListB);
57+
ReverseLinkedList = Reverse(LinkedListB);
5858
PrintLinkedList(ReverseLinkedList);
5959

6060
return ReverseLinkedList == LinkedListB;

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) KNSoft.org
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE

Main.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,37 @@
1-
#include "Public.h"
1+
#include "pch.h"
22

33
typedef struct _EXAMPLE_PROC
44
{
55
wchar_t* Name;
66
FN_EXAMPLE_PROC* Proc;
7-
} EXAMPLE_PROC, *PEXAMPLE_PROC;
7+
} EXAMPLE_PROC;
88

99
#define DECL_EXAMPLE_PROC(x) { L###x, &x }
1010

1111
/* Append new example here in alphabetical order */
1212

13-
extern FN_EXAMPLE_PROC DataStructure_LinkedListReverse;
13+
extern FN_EXAMPLE_PROC DataStructure_LinkedList_Reverse;
1414
extern FN_EXAMPLE_PROC Print_MultiplicationTable;
1515

1616
static const EXAMPLE_PROC ExampleList[] = {
17-
DECL_EXAMPLE_PROC(DataStructure_LinkedListReverse),
17+
DECL_EXAMPLE_PROC(DataStructure_LinkedList_Reverse),
1818
DECL_EXAMPLE_PROC(Print_MultiplicationTable),
1919
};
2020

21+
static
22+
bool
23+
RunExample(
24+
_In_ const EXAMPLE_PROC* Example)
25+
{
26+
bool bRet;
27+
28+
wprintf(L"======== Running example: %ls ========\n", Example->Name);
29+
bRet = Example->Proc();
30+
wprintf(L"======== %ls ========\n\n", bRet ? L"Succeeded" : L"Failed");
31+
32+
return bRet;
33+
}
34+
2135
int wmain(
2236
_In_ int argc,
2337
_In_reads_(argc) _Pre_z_ wchar_t** argv)
@@ -29,7 +43,7 @@ int wmain(
2943
/* No argument, run all examples */
3044
for (int i = 0; i < __crt_countof(ExampleList); i++)
3145
{
32-
if (!ExampleList[i].Proc())
46+
if (!RunExample(&ExampleList[i]))
3347
{
3448
return EFAULT;
3549
}
@@ -42,7 +56,7 @@ int wmain(
4256
{
4357
if (_wcsicmp(argv[1], ExampleList[i].Name) == 0)
4458
{
45-
return ExampleList[i].Proc() ? 0 : EFAULT;
59+
return RunExample(&ExampleList[i]) ? 0 : EFAULT;
4660
}
4761
}
4862
return ENOENT;

Print/MultiplicationTable.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "../Public.h"
1+
#include "pch.h"
22

33
_Function_class_(FN_EXAMPLE_PROC)
44
bool

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# C-Programming-Examples
2+
3+
[![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/KNSoft/C-Programming-Examples/msbuild.yml)](https://github.com/KNSoft/C-Programming-Examples/actions/workflows/msbuild.yml) [![GitHub License](https://img.shields.io/github/license/KNSoft/C-Programming-Examples)](https://github.com/KNSoft/C-Programming-Examples/blob/main/LICENSE)
4+
5+
[C-Programming-Examples](https://github.com/KNSoft/C-Programming-Examples) provides basic C programming examples for getting started with C language, data structures, and algorithms.
6+
7+
## Examples
8+
9+
- DataStructure
10+
- LinkedList
11+
- Reverse
12+
- Print
13+
- MultiplicationTable
14+
15+
16+
## License
17+
18+
[![GitHub License](https://img.shields.io/github/license/KNSoft/C-Programming-Examples)](https://github.com/KNSoft/C-Programming-Examples/blob/main/LICENSE)
19+
20+
[C-Programming-Examples](https://github.com/KNSoft/C-Programming-Examples) is licensed under the [MIT](https://github.com/KNSoft/C-Programming-Examples/blob/main/LICENSE) license.

Public.c renamed to pch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "Public.h"
1+
#include "pch.h"
22

33
#pragma region List
44

Public.h renamed to pch.h

File renamed without changes.

0 commit comments

Comments
 (0)