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
+109 -51

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 "Helper.h"
#include <Windows.h>
void pause() { void pause() {
printf("\n%s\n", "Press any key to continue. . ."); printf("\n%s\n", "Press any key to continue. . .");
getch(); getch();
} }
void clrscr() void clrscr() {
{ HANDLE hStdOut;
HANDLE hStdOut; CONSOLE_SCREEN_BUFFER_INFO csbi;
CONSOLE_SCREEN_BUFFER_INFO csbi; DWORD count;
DWORD count; DWORD cellCount;
DWORD cellCount; COORD homeCoords = { 0, 0 };
COORD homeCoords = { 0, 0 }; COORD consoleSize = { 24, 80 };
COORD consoleWipe = { 0, 0 };
int minx;
int miny;
hStdOut = GetStdHandle( STD_OUTPUT_HANDLE ); minx = GetSystemMetrics(SM_CXMIN);
if (hStdOut == INVALID_HANDLE_VALUE) return; miny = GetSystemMetrics(SM_CYMIN);
/* Get the number of cells in the current buffer */ hStdOut = GetStdHandle( STD_OUTPUT_HANDLE );
if (!GetConsoleScreenBufferInfo( hStdOut, &csbi )) return; if (hStdOut == INVALID_HANDLE_VALUE) return;
cellCount = csbi.dwSize.X *csbi.dwSize.Y;
/* Fill the entire buffer with spaces */ // Get the number of cells in the current buffer
if (!FillConsoleOutputCharacter( if (!GetConsoleScreenBufferInfo( hStdOut, &csbi )) return;
hStdOut, cellCount = csbi.dwSize.X *csbi.dwSize.Y;
(TCHAR) ' ', consoleSize = csbi.dwSize;
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 */ if (!SetConsoleScreenBufferSize(hStdOut, consoleWipe)) {
SetConsoleCursorPosition( hStdOut, homeCoords ); return;
} }
/*
if (!SetConsoleScreenBufferSize(hStdOut, consoleSize)) {
return;
}
*/
// 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" #include "Project4.h"
#define holdsize 5 #define holdsize 10
TtimeStruct holding[holdsize]; TtimeStruct* holding;
int i, j ,k = 0; int i, j ,k = 0;
void init() { void init() {
srand(time(NULL));
holding = (TtimeStruct*)malloc(sizeof(TtimeStruct) * holdsize);
for (i = 0; i < holdsize; i++) { for (i = 0; i < holdsize; i++) {
holding[i] = (TtimeStruct)malloc(sizeof(TravTimeStruct)); holding[i] = (TtimeStruct)malloc(sizeof(TravTimeStruct));
} }
@@ -17,9 +27,19 @@ void init() {
void getInputs() { void getInputs() {
for (i = 0; i < holdsize; i++) { for (i = 0; i < holdsize; i++) {
clrscr(); holding[i]->currentTimestamp = time(NULL);
printf("%s%d\n\n", "Input for #", i); holding[i]->distance = rand()%100;
printf("%s\n:", "Please enter a speed"); 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(); init();
getInputs(); getInputs();
printStructs();
pause();
down(); down();
pause();
return 0; return 0;
} }
@@ -38,4 +59,5 @@ void down() {
for (i = 0; i < holdsize; i++) { for (i = 0; i < holdsize; i++) {
free(holding[i]); free(holding[i]);
} }
free(holding);
} }
+12 -8
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 <conio.h>
#include <stdio.h> #include <stdio.h>
#include <memory.h> #include <memory.h>
#include <malloc.h> #include <malloc.h>
#include <time.h> #include <time.h>
#include <stdlib.h>
#define true 1; #define true 1;
#define false 0; #define false 0;
typedef struct typedef struct
{ {
float speed; int speed;
float distance; int distance;
float timetraveled; time_t currentTimestamp;
} TravTimeStruct, *TtimeStruct; } TravTimeStruct, *TtimeStruct;
#include "Helper.h"
void init();
void down();
void pause();
void clrscr();
@@ -83,6 +83,7 @@
<ClCompile Include="Project4.c" /> <ClCompile Include="Project4.c" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="Helper.h" />
<ClInclude Include="Project4.h" /> <ClInclude Include="Project4.h" />
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
@@ -21,10 +21,16 @@
<ClInclude Include="Project4.h"> <ClInclude Include="Project4.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Helper.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="Project4.c"> <ClCompile Include="Project4.c">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="Helper.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
</Project> </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