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 = Phase6_Prep.c StringUtils.c
OBJECTS = Phase6_Prep.o StringUtils.o
# Uses the template structure defined in the TypicalUtils folder
all: Phase6_Prep
Phase6_Prep: $(OBJECTS)
$(CC) $(OBJECTS) -o Phase6_Prep
Phase6_Prep.o: Phase6_Prep.c
$(CC) -c Phase6_Prep.c -o Phase6_Prep.o
StringUtils.o: StringUtils.c
$(CC) -c StringUtils.c -o StringUtils.o
clean:
rm -f $(OBJECTS) Phase6_Prep Phase6_Prep.out
clean_objects:
rm -f $(OBJECTS)
run:
./Phase6_Prep
run_win:
Phase6_Prep

View file

@ -0,0 +1,47 @@
// header files
#include "StringUtils.h"
// constants
/*
Name: main
Process: Runs the String Utilities
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
printf("\n---Phase 6: All String Utilities---\n");
printf("=====================================\n");
// get user input
// do calculations
// string length
// getStringLength
// string copy
// copyString
// string concatenate
// catString
// string compare (<, >, =)
// compareString
// string substring get
// substringGet
// string substring find
// substringFind
// string set to lower
// lowerString
// string get to delimiter
// stringDelimiter
// string get to end of line
// stringEOL
// display results
printf("\nProgram End\n");
// return success
return 0;
}

View file

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

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,163 @@
// header files
#include "StringUtils.h"
// list of utils:
// string length
// getStringLength
// string copy
// copyString
// string concatenate
// catString
// string compare (<, >, =)
// compareString
// string substring get
// getSubString
// string substring find
// findSubString
// string set to lower
// lowerString
// string get to delimiter
// stringDelimiter
// string get to end of line
// stringEOL
// function implementations
/*
Name: catString
Process: concatenates two strings
Function input/parameters: c-style string (char *)
Function output/parameters: c-style string (char *)
Function output/returned: NONE
Device input/---: NONE
Device output/---: NONE
Dependencies: getStringLength
*/
void catString(char *outString, const char *inString)
{
// no return, void.
}
/*
Name: compareString
Process: compares two strings as follows:
- if left string is alphabetically greater than the right string,
returns value greater than zero
- if left string is alphabetically less than the right string,
returns value less than zero
- if strings are alphabetically equal but one is longer,
longer one is greater
- otherwise, returns zero
Function input/parameters: c-style strings (char *) [first and second/left&right]
Function output/parameters: NONE
Function output/returned: results as specfifed above (int)
Device input/---: NONE
Device output/---: NONE
Dependencies: getStringLength
*/
int compareString(const char *firstString, const char *secondString)
{
// return zero (temp)
return 0;
}
/*
Name: copyString
Process: copies string into new string variable, overwrites destination.
Function input/parameters: c-style string (char *)
Function output/parameters: c-style string (char *)
Function output/returned: NONE
Device input/---: NONE
Device output/---: NONE
Dependencies: getStringLength
*/
void copyString(char *outString, const char *inString)
{
// no return, void.
}
/*
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;
}
/*
Name: getSubString
Process: captures sub string within larger string
between two inclusive indices.
returns empty string if either index is out of range,
assumes enough memory in dest string
Function input/parameters: ???
Function output/parameters: NONE
Function output/returned: ???
Device input/---: NONE
Device output/---: NONE
Dependencies: included by standard libraries
*/
/*
Name: findSubString
Process: ???
Function input/parameters: ???
Function output/parameters: NONE
Function output/returned: ???
Device input/---: NONE
Device output/---: NONE
Dependencies: included by standard libraries
*/
/*
Name: ???
Process: ???
Function input/parameters: ???
Function output/parameters: NONE
Function output/returned: ???
Device input/---: NONE
Device output/---: NONE
Dependencies: included by standard libraries
*/
/*
Name: ???
Process: ???
Function input/parameters: ???
Function output/parameters: NONE
Function output/returned: ???
Device input/---: NONE
Device output/---: NONE
Dependencies: included by standard libraries
*/
/*
Name: ???
Process: ???
Function input/parameters: ???
Function output/parameters: NONE
Function output/returned: ???
Device input/---: NONE
Device output/---: NONE
Dependencies: included by standard libraries
*/

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