Skip to content

Commit 9235a6f

Browse files
committed
Add code
0 parents  commit 9235a6f

File tree

8 files changed

+294
-0
lines changed

8 files changed

+294
-0
lines changed

LineCounter/LineCounter.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// LineCounter.cpp : Defines the entry point for the console application.
2+
//
3+
4+
#include "stdafx.h"
5+
using namespace std;
6+
7+
#pragma comment(lib, "User32.lib")
8+
9+
int main(int argc, char* argv[])
10+
{
11+
WIN32_FIND_DATA ffd;
12+
13+
string dir;
14+
if (argc != 2)
15+
{
16+
dir = _getcwd(nullptr, 0);
17+
printf("Warning: No directory given, assuming %s\n", dir.c_str());
18+
printf("Standard usage: %s <directory path>\n\n", argv[0]);
19+
}
20+
else
21+
dir = argv[1];
22+
23+
cout << "Target directory is " << dir << endl;
24+
25+
_chdir(dir.c_str());
26+
27+
dir += "\\*";
28+
29+
HANDLE find = INVALID_HANDLE_VALUE;
30+
find = FindFirstFile(dir.c_str(), &ffd);
31+
32+
if (find == INVALID_HANDLE_VALUE)
33+
{
34+
cerr << "No files found!\n";
35+
return 1;
36+
}
37+
38+
ifstream in;
39+
40+
uintmax_t sum(0);
41+
42+
do
43+
{
44+
if (ffd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
45+
continue;
46+
47+
48+
in.open(ffd.cFileName, ios::in);
49+
size_t len(0);
50+
while (in.good())
51+
{
52+
getline(in, dir);
53+
++len;
54+
}
55+
in.clear();
56+
in.close();
57+
58+
sum += len;
59+
60+
cout << "\tFile " << ffd.cFileName << ": " << len << " lines.\n";
61+
cout << "\t\tRunning total: " << sum << endl << endl;
62+
} while (FindNextFile(find, &ffd));
63+
64+
char msg[9001];
65+
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|80, NULL, GetLastError(), 0, msg, 9001, NULL);
66+
cout << "\n\n" << msg;
67+
68+
cout << "\n\nTotal number of lines in files in the directory " << _getcwd(NULL,NULL) << ": " << sum << ".\n";
69+
return 0;
70+
}
71+

LineCounter/LineCounter.vcxproj

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="12.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+
</ItemGroup>
13+
<PropertyGroup Label="Globals">
14+
<ProjectGuid>{F73B42F1-EF98-4274-A0B8-9BAA815E9C53}</ProjectGuid>
15+
<Keyword>Win32Proj</Keyword>
16+
<RootNamespace>LineCounter</RootNamespace>
17+
</PropertyGroup>
18+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
19+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
20+
<ConfigurationType>Application</ConfigurationType>
21+
<UseDebugLibraries>true</UseDebugLibraries>
22+
<PlatformToolset>v120</PlatformToolset>
23+
<CharacterSet>NotSet</CharacterSet>
24+
</PropertyGroup>
25+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
26+
<ConfigurationType>Application</ConfigurationType>
27+
<UseDebugLibraries>false</UseDebugLibraries>
28+
<PlatformToolset>v120</PlatformToolset>
29+
<WholeProgramOptimization>true</WholeProgramOptimization>
30+
<CharacterSet>NotSet</CharacterSet>
31+
</PropertyGroup>
32+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
33+
<ImportGroup Label="ExtensionSettings">
34+
</ImportGroup>
35+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
36+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
37+
</ImportGroup>
38+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
39+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
40+
</ImportGroup>
41+
<PropertyGroup Label="UserMacros" />
42+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
43+
<LinkIncremental>true</LinkIncremental>
44+
</PropertyGroup>
45+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
46+
<LinkIncremental>false</LinkIncremental>
47+
</PropertyGroup>
48+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
49+
<ClCompile>
50+
<PrecompiledHeader>Use</PrecompiledHeader>
51+
<WarningLevel>EnableAllWarnings</WarningLevel>
52+
<Optimization>Disabled</Optimization>
53+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
54+
<SDLCheck>true</SDLCheck>
55+
<MultiProcessorCompilation>true</MultiProcessorCompilation>
56+
<StringPooling>true</StringPooling>
57+
<EnableParallelCodeGeneration>true</EnableParallelCodeGeneration>
58+
<EnableEnhancedInstructionSet>AdvancedVectorExtensions</EnableEnhancedInstructionSet>
59+
</ClCompile>
60+
<Link>
61+
<SubSystem>Console</SubSystem>
62+
<GenerateDebugInformation>true</GenerateDebugInformation>
63+
</Link>
64+
</ItemDefinitionGroup>
65+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
66+
<ClCompile>
67+
<WarningLevel>Level3</WarningLevel>
68+
<PrecompiledHeader>Use</PrecompiledHeader>
69+
<Optimization>Full</Optimization>
70+
<FunctionLevelLinking>true</FunctionLevelLinking>
71+
<IntrinsicFunctions>true</IntrinsicFunctions>
72+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
73+
<SDLCheck>true</SDLCheck>
74+
<MultiProcessorCompilation>true</MultiProcessorCompilation>
75+
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
76+
<FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
77+
<StringPooling>true</StringPooling>
78+
<EnableParallelCodeGeneration>true</EnableParallelCodeGeneration>
79+
<EnableEnhancedInstructionSet>AdvancedVectorExtensions</EnableEnhancedInstructionSet>
80+
<CallingConvention>VectorCall</CallingConvention>
81+
</ClCompile>
82+
<Link>
83+
<SubSystem>Console</SubSystem>
84+
<GenerateDebugInformation>true</GenerateDebugInformation>
85+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
86+
<OptimizeReferences>true</OptimizeReferences>
87+
<SetChecksum>true</SetChecksum>
88+
</Link>
89+
</ItemDefinitionGroup>
90+
<ItemGroup>
91+
<Text Include="ReadMe.txt" />
92+
</ItemGroup>
93+
<ItemGroup>
94+
<ClInclude Include="stdafx.h" />
95+
<ClInclude Include="targetver.h" />
96+
</ItemGroup>
97+
<ItemGroup>
98+
<ClCompile Include="LineCounter.cpp" />
99+
<ClCompile Include="stdafx.cpp">
100+
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
101+
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
102+
</ClCompile>
103+
</ItemGroup>
104+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
105+
<ImportGroup Label="ExtensionTargets">
106+
</ImportGroup>
107+
</Project>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
<Text Include="ReadMe.txt" />
19+
</ItemGroup>
20+
<ItemGroup>
21+
<ClInclude Include="stdafx.h">
22+
<Filter>Header Files</Filter>
23+
</ClInclude>
24+
<ClInclude Include="targetver.h">
25+
<Filter>Header Files</Filter>
26+
</ClInclude>
27+
</ItemGroup>
28+
<ItemGroup>
29+
<ClCompile Include="stdafx.cpp">
30+
<Filter>Source Files</Filter>
31+
</ClCompile>
32+
<ClCompile Include="LineCounter.cpp">
33+
<Filter>Source Files</Filter>
34+
</ClCompile>
35+
</ItemGroup>
36+
</Project>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup />
4+
</Project>

LineCounter/ReadMe.txt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
========================================================================
2+
CONSOLE APPLICATION : LineCounter Project Overview
3+
========================================================================
4+
5+
AppWizard has created this LineCounter application for you.
6+
7+
This file contains a summary of what you will find in each of the files that
8+
make up your LineCounter application.
9+
10+
11+
LineCounter.vcxproj
12+
This is the main project file for VC++ projects generated using an Application Wizard.
13+
It contains information about the version of Visual C++ that generated the file, and
14+
information about the platforms, configurations, and project features selected with the
15+
Application Wizard.
16+
17+
LineCounter.vcxproj.filters
18+
This is the filters file for VC++ projects generated using an Application Wizard.
19+
It contains information about the association between the files in your project
20+
and the filters. This association is used in the IDE to show grouping of files with
21+
similar extensions under a specific node (for e.g. ".cpp" files are associated with the
22+
"Source Files" filter).
23+
24+
LineCounter.cpp
25+
This is the main application source file.
26+
27+
/////////////////////////////////////////////////////////////////////////////
28+
Other standard files:
29+
30+
StdAfx.h, StdAfx.cpp
31+
These files are used to build a precompiled header (PCH) file
32+
named LineCounter.pch and a precompiled types file named StdAfx.obj.
33+
34+
/////////////////////////////////////////////////////////////////////////////
35+
Other notes:
36+
37+
AppWizard uses "TODO:" comments to indicate parts of the source code you
38+
should add to or customize.
39+
40+
/////////////////////////////////////////////////////////////////////////////

LineCounter/stdafx.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// stdafx.cpp : source file that includes just the standard includes
2+
// LineCounter.pch will be the pre-compiled header
3+
// stdafx.obj will contain the pre-compiled type information
4+
5+
#include "stdafx.h"
6+
7+
// TODO: reference any additional headers you need in STDAFX.H
8+
// and not in this file

LineCounter/stdafx.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// stdafx.h : include file for standard system include files,
2+
// or project specific include files that are used frequently, but
3+
// are changed infrequently
4+
//
5+
6+
#pragma once
7+
8+
#include "targetver.h"
9+
10+
#include <direct.h>
11+
#include <stdio.h>
12+
#include <Windows.h>
13+
#include <fstream>
14+
#include <iostream>
15+
#include <string>
16+
#include <stdint.h>
17+
18+
19+
20+
// TODO: reference additional headers your program requires here

LineCounter/targetver.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#pragma once
2+
3+
// Including SDKDDKVer.h defines the highest available Windows platform.
4+
5+
// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
6+
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
7+
8+
#include <SDKDDKVer.h>

0 commit comments

Comments
 (0)