preliminary implimentation of dynamic-sized input
This commit is contained in:
parent
cb01b27501
commit
4c9614342e
@ -13,12 +13,14 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="src\caesarcrypt.c" />
|
<ClCompile Include="src\caesarcrypt.c" />
|
||||||
<ClCompile Include="src\crypt.c" />
|
<ClCompile Include="src\crypt.c" />
|
||||||
|
<ClCompile Include="src\dyninput.c" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="caesarcrypt.licenseheader" />
|
<None Include="caesarcrypt.licenseheader" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="src\crypt.h" />
|
<ClInclude Include="src\crypt.h" />
|
||||||
|
<ClInclude Include="src\dyninput.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<PropertyGroup Label="Globals">
|
<PropertyGroup Label="Globals">
|
||||||
<VCProjectVersion>16.0</VCProjectVersion>
|
<VCProjectVersion>16.0</VCProjectVersion>
|
||||||
|
@ -21,6 +21,9 @@
|
|||||||
<ClCompile Include="src\crypt.c">
|
<ClCompile Include="src\crypt.c">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="src\dyninput.c">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="caesarcrypt.licenseheader" />
|
<None Include="caesarcrypt.licenseheader" />
|
||||||
@ -29,5 +32,8 @@
|
|||||||
<ClInclude Include="src\crypt.h">
|
<ClInclude Include="src\crypt.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="src\dyninput.h">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
@ -9,6 +9,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "crypt.h"
|
#include "crypt.h"
|
||||||
|
#include "dyninput.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -28,10 +29,11 @@ int main()
|
|||||||
fgets(buf, 3, stdin);
|
fgets(buf, 3, stdin);
|
||||||
int choice = strtol(buf, NULL, 10);
|
int choice = strtol(buf, NULL, 10);
|
||||||
|
|
||||||
char* msg = calloc(128, sizeof(char));
|
//char* msg = calloc(128, sizeof(char));
|
||||||
|
|
||||||
fputs("Enter your message text: ", stdout);
|
fputs("Enter your message text: ", stdout);
|
||||||
if (msg) fgets(msg, 128, stdin);
|
//if (msg) fgets(msg, 128, stdin);
|
||||||
|
char* msg = dyninput_str(INT64_MAX);
|
||||||
|
|
||||||
fputs("Enter your key (shift value): ", stdout);
|
fputs("Enter your key (shift value): ", stdout);
|
||||||
fgets(buf, 4, stdin);
|
fgets(buf, 4, stdin);
|
||||||
@ -56,5 +58,7 @@ int main()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(msg);
|
||||||
|
msg = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
47
src/dyninput.c
Normal file
47
src/dyninput.c
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Filename: dyninput.c
|
||||||
|
* Authors(s): Roland (Roland@example.com)
|
||||||
|
* Description: Short description here
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
|
char* dyninput_str(int_least64_t maxsize)
|
||||||
|
{
|
||||||
|
char* str = malloc(3 * sizeof(char));
|
||||||
|
/*if (!str)
|
||||||
|
puts("Error allocating memory!");
|
||||||
|
return NULL;*/
|
||||||
|
|
||||||
|
int_least64_t size = 3, i = 0;
|
||||||
|
char c = 0;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
c = getchar();
|
||||||
|
if (i + 2 == size)
|
||||||
|
{
|
||||||
|
char* tmp = realloc(str, size + 1);
|
||||||
|
if (!tmp)
|
||||||
|
{
|
||||||
|
puts("Error (re)allocating memory!");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
str = tmp;
|
||||||
|
size++;
|
||||||
|
}
|
||||||
|
|
||||||
|
str[i] = c;
|
||||||
|
i++;
|
||||||
|
} while (c && c != '\n');
|
||||||
|
str[i] = '\0';
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
16
src/dyninput.h
Normal file
16
src/dyninput.h
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
/*
|
||||||
|
* Filename: dyninput.h
|
||||||
|
* Authors(s): Roland (r.weirhowell@gmail.com)
|
||||||
|
* Description: Header file for dyninput.c
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
|
char* dyninput_str(int_least64_t maxsize);
|
Loading…
x
Reference in New Issue
Block a user