Project 4

Signed-off-by: Amrit Panesar <apanesar@4195tech.com>
This commit is contained in:
Amrit Panesar committed 2015-09-08 20:33:39 -07:00
1 parent d4329f2c52
commit 70d7faed2c
10 files changed
+110 -52

No files matched your search

Binary file not shown.
Binary file not shown.
+37 -34
View File
@@ -1,45 +1,48 @@
#include "Project4.h"
#include <Windows.h>
#include "Helper.h"
void pause() {
printf("\n%s\n", "Press any key to continue. . .");
getch();
}
void clrscr()
{
HANDLE hStdOut;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD count;
DWORD cellCount;
COORD homeCoords = { 0, 0 };
void clrscr() {
HANDLE hStdOut;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD count;
DWORD cellCount;
COORD homeCoords = { 0, 0 };
COORD consoleSize = { 24, 80 };
COORD consoleWipe = { 0, 0 };
int minx;
int miny;
hStdOut = GetStdHandle( STD_OUTPUT_HANDLE );
if (hStdOut == INVALID_HANDLE_VALUE) return;
minx = GetSystemMetrics(SM_CXMIN);
miny = GetSystemMetrics(SM_CYMIN);
/* Get the number of cells in the current buffer */
if (!GetConsoleScreenBufferInfo( hStdOut, &csbi )) return;
cellCount = csbi.dwSize.X *csbi.dwSize.Y;
hStdOut = GetStdHandle( STD_OUTPUT_HANDLE );
if (hStdOut == INVALID_HANDLE_VALUE) return;
/* Fill the entire buffer with spaces */
if (!FillConsoleOutputCharacter(
hStdOut,
(TCHAR) ' ',
cellCount,
homeCoords,
&count
)) return;
// Get the number of cells in the current buffer
if (!GetConsoleScreenBufferInfo( hStdOut, &csbi )) return;
cellCount = csbi.dwSize.X *csbi.dwSize.Y;
consoleSize = csbi.dwSize;
/* Fill the entire buffer with the current colors and attributes */
if (!FillConsoleOutputAttribute(
hStdOut,
csbi.wAttributes,
cellCount,
homeCoords,
&count
)) return;
if (!SetConsoleScreenBufferSize(hStdOut, consoleWipe)) {
return;
}
/*
if (!SetConsoleScreenBufferSize(hStdOut, consoleSize)) {
return;
}
*/
/* Move the cursor home */
SetConsoleCursorPosition( hStdOut, homeCoords );
}
// Fill the entire buffer with spaces
if (!FillConsoleOutputCharacter(hStdOut, (TCHAR) ' ', cellCount, homeCoords, &count)) return;
// Fill the entire buffer with the current colors and attributes
if (!FillConsoleOutputAttribute(hStdOut, csbi.wAttributes, cellCount, homeCoords, &count)) return;
// Move the cursor home
SetConsoleCursorPosition( hStdOut, homeCoords );
}
+9
View File
@@ -0,0 +1,9 @@
#include <Windows.h>
#include <conio.h>
#include <stdlib.h>
#include <stdio.h>
void init();
void down();
void pause();
void clrscr();
+31 -9
View File
@@ -1,15 +1,25 @@
// Project4.cpp : Defines the entry point for the console application.
//
/******************************************************************************
* Author: Amrit Panesar
* Project: 4 - Structs/Malloc
* Date: 09/08/2015
* Purpose: Create a multidimensional array on the fly and populate its children
* Display the results.
*****************************************************************************/
#include "Project4.h"
#define holdsize 5
#define holdsize 10
TtimeStruct holding[holdsize];
TtimeStruct* holding;
int i, j ,k = 0;
void init() {
srand(time(NULL));
holding = (TtimeStruct*)malloc(sizeof(TtimeStruct) * holdsize);
for (i = 0; i < holdsize; i++) {
holding[i] = (TtimeStruct)malloc(sizeof(TravTimeStruct));
}
@@ -17,9 +27,19 @@ void init() {
void getInputs() {
for (i = 0; i < holdsize; i++) {
clrscr();
printf("%s%d\n\n", "Input for #", i);
printf("%s\n:", "Please enter a speed");
holding[i]->currentTimestamp = time(NULL);
holding[i]->distance = rand()%100;
holding[i]->speed = rand()%100;
}
}
void printStructs() {
for (i = 0; i < holdsize; i++) {
printf("%s%d\n", "Structure #", i);
printf("%s%d\n", "Time: ", holding[i]->currentTimestamp);
printf("%s%d\n", "Distance: ", holding[i]->distance);
printf("%s%d\n", "Speed: ", holding[i]->speed);
printf("%s\n\n", "-----------------------");
}
}
@@ -27,10 +47,11 @@ int main(int argc, char **argv) {
init();
getInputs();
pause();
printStructs();
down();
pause();
return 0;
}
@@ -38,4 +59,5 @@ void down() {
for (i = 0; i < holdsize; i++) {
free(holding[i]);
}
free(holding);
}
+13 -9
View File
@@ -1,22 +1,26 @@
/******************************************************************************
* Author: Amrit Panesar
* Project: 4 - Structs/Malloc
* Date: 09/08/2015
* Purpose: Create a multidimensional array on the fly and populate its children
* Display the results.
*****************************************************************************/
#include <conio.h>
#include <stdio.h>
#include <memory.h>
#include <malloc.h>
#include <time.h>
#include <stdlib.h>
#define true 1;
#define false 0;
typedef struct
typedef struct
{
float speed;
float distance;
float timetraveled;
int speed;
int distance;
time_t currentTimestamp;
} TravTimeStruct, *TtimeStruct;
void init();
void down();
void pause();
void clrscr();
#include "Helper.h"
@@ -83,6 +83,7 @@
<ClCompile Include="Project4.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Helper.h" />
<ClInclude Include="Project4.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
@@ -21,10 +21,16 @@
<ClInclude Include="Project4.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Helper.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Project4.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Helper.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
Binary file not shown.
+13
View File
@@ -0,0 +1,13 @@
@echo off
SET st2Path=C:\Program Files\Sublime Text 3\sublime_text.exe
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text" /t REG_SZ /v "" /d "Open with Sublime Text" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text" /t REG_EXPAND_SZ /v "Icon" /d "%st2Path%,0" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text\command" /t REG_SZ /v "" /d "%st2Path% \"%%1\"" /f
@reg add "HKEY_CLASSES_ROOT\Folder\shell\Open with Sublime Text" /t REG_SZ /v "" /d "Open with Sublime Text" /f
@reg add "HKEY_CLASSES_ROOT\Folder\shell\Open with Sublime Text" /t REG_EXPAND_SZ /v "Icon" /d "%st2Path%,0" /f
@reg add "HKEY_CLASSES_ROOT\Folder\shell\Open with Sublime Text\command" /t REG_SZ /v "" /d "%st2Path% \"%%1\"" /f
pause