Skip to content

Commit 4deb1e4

Browse files
ChristopherChristopher
authored andcommitted
from char to char works
1 parent fa4ec6f commit 4deb1e4

File tree

8 files changed

+93
-0
lines changed

8 files changed

+93
-0
lines changed

FileCreator/FileCreator.cpp

1.6 KB
Binary file not shown.

FileCreator/FileCreator.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,14 @@
148148
</ItemDefinitionGroup>
149149
<ItemGroup>
150150
<ClInclude Include="DataFile.h" />
151+
<ClInclude Include="FixedSizeRegister.h" />
151152
<ClInclude Include="stdafx.h" />
152153
<ClInclude Include="targetver.h" />
153154
</ItemGroup>
154155
<ItemGroup>
155156
<ClCompile Include="DataFile.cpp" />
156157
<ClCompile Include="FileCreator.cpp" />
158+
<ClCompile Include="FixedSizeRegister.cpp" />
157159
<ClCompile Include="stdafx.cpp">
158160
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
159161
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>

FileCreator/FileCreator.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
<ClInclude Include="DataFile.h">
2525
<Filter>Header Files</Filter>
2626
</ClInclude>
27+
<ClInclude Include="FixedSizeRegister.h">
28+
<Filter>Header Files</Filter>
29+
</ClInclude>
2730
</ItemGroup>
2831
<ItemGroup>
2932
<ClCompile Include="stdafx.cpp">
@@ -35,5 +38,8 @@
3538
<ClCompile Include="DataFile.cpp">
3639
<Filter>Source Files</Filter>
3740
</ClCompile>
41+
<ClCompile Include="FixedSizeRegister.cpp">
42+
<Filter>Source Files</Filter>
43+
</ClCompile>
3844
</ItemGroup>
3945
</Project>

FileCreator/FixedSizeRegister.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include "stdafx.h"
2+
#include "FixedSizeRegister.h"
3+
4+
FixedSizeRegister::FixedSizeRegister()
5+
{
6+
this->dataFile = new DataFile((char*)"fixedSizeFile");
7+
this->name = new char[30];
8+
this->job = new char[20];
9+
}
10+
11+
void FixedSizeRegister::printRegister()
12+
{
13+
}
14+
15+
char * FixedSizeRegister::toChar()
16+
{
17+
char * data = new char[sizeof(int) + 30 + 20 + sizeof(salary)];
18+
19+
memcpy(data, reinterpret_cast<char*>(&id), sizeof(int));
20+
21+
memcpy(data + sizeof(id), name, 30);
22+
23+
memcpy(data + sizeof(id) + 30, reinterpret_cast<char*>(&salary), sizeof(salary));
24+
25+
memcpy(data + sizeof(id) + 30 + sizeof(salary), job, 20);
26+
27+
return data;
28+
}
29+
30+
void FixedSizeRegister::fromChar(char * data)
31+
{
32+
memcpy(&this->id, data, sizeof(this->id));
33+
34+
memcpy(this->name, data + sizeof(this->id), 30);
35+
36+
memcpy(reinterpret_cast<char*>(&salary), data + sizeof(this->id) + 30, sizeof(this->salary));
37+
38+
memcpy(job, data + sizeof(this->id) + 30 + sizeof(this->salary), 20);
39+
}
40+
41+
void FixedSizeRegister::openFile(char * name)
42+
{
43+
}
44+
45+
void FixedSizeRegister::writeIntoFile()
46+
{
47+
}
48+
49+
void FixedSizeRegister::readIntoFile(int position)
50+
{
51+
}
52+
53+
void FixedSizeRegister::closeFile()
54+
{
55+
}
56+
57+
int FixedSizeRegister::getSize()
58+
{
59+
return sizeof(this->id) + sizeof(this->name) + sizeof(this->job) + +sizeof(this->salary);
60+
}

FileCreator/FixedSizeRegister.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#pragma once
2+
3+
#include "DataFile.h"
4+
5+
class FixedSizeRegister
6+
{
7+
private:
8+
DataFile * dataFile;
9+
unsigned int id;
10+
char * name;
11+
double salary;
12+
char * job;
13+
14+
public:
15+
FixedSizeRegister();
16+
void printRegister();
17+
char* toChar();
18+
void fromChar(char* data);
19+
void openFile(char* name);
20+
void writeIntoFile();
21+
void readIntoFile(int position);
22+
void closeFile();
23+
int getSize();
24+
};
25+

FileCreator/fixedSizeFile

Whitespace-only changes.

FileCreator/products.bin

36 Bytes
Binary file not shown.

FileCreator/stdafx.h

84 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)