Good Stopping point for CS480 Prep

++ Phases 1-6 Preparation
++ C, H, Makefiles
This commit is contained in:
Charles Descamps 2024-01-06 21:56:16 -07:00
parent b861b15368
commit ca321e6c4e
19 changed files with 889 additions and 0 deletions

View file

@ -0,0 +1,28 @@
CC = gcc -Wall
SOURCES = Phase5_Prep.c StringUtils.c
OBJECTS = Phase5_Prep.o StringUtils.o
# Uses the template structure defined in the TypicalUtils folder
all: Phase5_Prep
Phase5_Prep: $(OBJECTS)
$(CC) $(OBJECTS) -o Phase5_Prep
Phase5_Prep.o: Phase5_Prep.c
$(CC) -c Phase5_Prep.c -o Phase5_Prep.o
StringUtils.o: StringUtils.c
$(CC) -c StringUtils.c -o StringUtils.o
clean:
rm -f $(OBJECTS) Phase5_Prep Phase5_Prep.out
clean_objects:
rm -f $(OBJECTS)
run:
./Phase5_Prep
run_win:
Phase5_Prep

View file

@ -0,0 +1,32 @@
// header files
#include "StringUtils.h"
// constants
/*
Name: main
Process: Runs all the functions listed above that was used as preparation for
CS480. Videos were used as the similar practice.
Function input/parameters: NONE
Function output/parameters: NONE
Function output/returned: NONE
Device input/---: NONE
Device output/---: NONE
Dependencies: included by standard libraries
*/
int main()
{
// define/initialize variables
int stringLen = 0;
char newString[] = "This is my new string!!!";
printf("\n---Phase 5: Getting String Length---\n");
printf("====================================\n");
// get user input
// do calculations
stringLen = getStringLength(newString);
// display results
printf("\nThe length of string '%s' is %d.\n", newString, stringLen);
printf("\nProgram End\n");
// return success
return 0;
}

View file

@ -0,0 +1,11 @@
#ifndef PHASE5PREP
#define PHASE5PREP
// header files
#include "StringUtils.h"
// data structures
// function prototypes
#endif // PHASE5PREP

View file

@ -0,0 +1,73 @@
// Preprocessor directives
#ifndef STANDARD_CONSTANTS_H
#define STANDARD_CONSTANTS_H
// Include Boolean
#include <stdbool.h>
// global constants
// constant for end of c-string null character
#define CARRIAGE_RETURN_CHAR '\r'
//constant for a COLON
#define COLON ':'
//constant for a COMMA
#define COMMA ','
//Constant to print a dash
#define DASH '-'
// highest printable character
#define HIGHEST_PRINTABLE_CHAR '~'
// constant for huge string length
#define HUGE_STR_LEN 256
// lowest printable character
#define LOWEST_PRINTABLE_CHAR ' '
// constant for small string length
#define MIN_STR_LEN 32
// constant for maximum string length
#define MAX_STR_LEN 128
// constant for end of c-string null character
#define NEWLINE_CHAR '\n'
// first non-printable above ASCII
#define DELETE_KEY 127
// constant for end of c-string null character
#define NULL_CHAR '\0'
// columns found in grade sheet before grading columns
#define NUM_BASE_COLS 5
// constant for number of grading frequency bins
#define NUM_FREQUENCY_BINS 10
//Constant for printing a pipe
#define PIPE '|'
//Constant for a period
#define PERIOD '.'
//Constant for PRECISION, 2 digits
#define PRECISION_2 2
//Constant for PRECISION, 4 digits
#define PRECISION_4 4
// constant for space character
#define SPACE ' '
// constant for standard string length
#define STD_STR_LEN 64
// constant for smallest string length
#define TINY_STR_LEN 16
#endif // STANDARD_CONSTANTS

View file

@ -0,0 +1,32 @@
// header files
#include "StringUtils.h"
// function implementations
/*
Name: getStringLength
Process: gets length of string from start to NULL_CHAR ('\0')
Function input/parameters: c-style string (char *)
Function output/parameters: NONE
Function output/returned: length of string (int)
Device input/---: NONE
Device output/---: NONE
Dependencies: included by standard libraries
*/
int getStringLength(const char *stringIn)
{
// define variables
int stringLength = 0, currentCharacter = 0;
// get user input (not needed)
// do calculations
while (currentCharacter < STD_STR_LEN && stringIn[currentCharacter] != NULL_CHAR)
{
// increment string length
stringLength = stringLength + 1;
// increment currentCharacter
currentCharacter = currentCharacter + 1;
}
// display results (not needed)
// return success
return stringLength;
}

View file

@ -0,0 +1,28 @@
#ifndef STRINGUTILSPREP
#define STRINGUTILSPREP
// header files
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>
#include "StandardConstants.h"
// data structures
// function prototypes
/*
Name: getStringLength
Process: counts length of string from start to NULL_CHAR ('\0')
Function input/parameters: c-style string (char *)
Function output/parameters: NONE
Function output/returned: length of string (int)
Device input/---: NONE
Device output/---: NONE
Dependencies: included by standard libraries
*/
int getStringLength(const char *stringLen);
#endif // STRINGUTILSPREP