Good Stopping point for CS480 Prep
++ Phases 1-6 Preparation ++ C, H, Makefiles
This commit is contained in:
parent
b861b15368
commit
ca321e6c4e
19 changed files with 889 additions and 0 deletions
83
Preparation/CS480_Prep.c
Normal file
83
Preparation/CS480_Prep.c
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
// header files
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
// constants
|
||||
|
||||
/*
|
||||
Name: add_two_nums
|
||||
Process: adds two numbers together given user input
|
||||
Function input/parameters: NONE
|
||||
Function output/parameters: NONE
|
||||
Function output/returned: NONE
|
||||
Device input/---: NONE
|
||||
Device output/---: NONE
|
||||
Dependencies: included by standard libraries
|
||||
*/
|
||||
int add_two_nums()
|
||||
{
|
||||
// define variables
|
||||
int first_num, second_num, total;
|
||||
// get user input
|
||||
printf("---Adding two numbers---\nPlease enter two numbers(space in between): ");
|
||||
scanf("%d %d", &first_num, &second_num);
|
||||
// do calculations
|
||||
total = first_num + second_num;
|
||||
// display results
|
||||
printf("\n%d + %d = %d!", first_num, second_num, total);
|
||||
// return success
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
Name: add_two_nums_parameterized
|
||||
Process: adds two numbers together given user input as parameters
|
||||
Function input/parameters:
|
||||
Function output/parameters: NONE
|
||||
Function output/returned: NONE
|
||||
Device input/---: NONE
|
||||
Device output/---: NONE
|
||||
Dependencies: included by standard libraries
|
||||
*/
|
||||
int add_two_nums_parameterized(int first_num, int second_num)
|
||||
{
|
||||
// define variables
|
||||
int total;
|
||||
// get user input
|
||||
printf("---Adding two numbers PARAMETERIZED!---\n");
|
||||
// do calculations
|
||||
total = first_num + second_num;
|
||||
// display results
|
||||
printf("\n%d + %d = %d!", first_num, second_num, total);
|
||||
// return total
|
||||
return total;
|
||||
}
|
||||
|
||||
/*
|
||||
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 tnNum1, tnNum2, tnSum;
|
||||
// get user input
|
||||
printf("Please input numbers for the parameterized version of adding two numbers.\n");
|
||||
scanf("%d", &tnNum1);
|
||||
scanf("%d", &tnNum2);
|
||||
// do calculations
|
||||
add_two_nums();
|
||||
tnSum = add_two_nums_parameterized(tnNum1, tnNum2);
|
||||
// display results
|
||||
// return success
|
||||
return 0;
|
||||
}
|
||||
35
Preparation/CS480_Prep.h
Normal file
35
Preparation/CS480_Prep.h
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#ifndef CS480PREP
|
||||
#define CS480PREP
|
||||
|
||||
// header files
|
||||
|
||||
// data structures
|
||||
|
||||
// function headers
|
||||
|
||||
/*
|
||||
Name: add_two_nums
|
||||
Process: adds two numbers together given user input
|
||||
Function input/parameters: NONE
|
||||
Function output/parameters: NONE
|
||||
Function output/returned: NONE
|
||||
Device input/---: NONE
|
||||
Device output/---: NONE
|
||||
Dependencies: included by standard libraries
|
||||
*/
|
||||
int add_two_nums();
|
||||
|
||||
/*
|
||||
Name: add_two_nums_parameterized
|
||||
Process: adds two numbers together given user input as parameters
|
||||
Function input/parameters: int first_num,
|
||||
int second_num
|
||||
Function output/parameters: int sum
|
||||
Function output/returned: NONE
|
||||
Device input/---: NONE
|
||||
Device output/---: NONE
|
||||
Dependencies: included by standard libraries
|
||||
*/
|
||||
int add_two_nums_parameterized(int first_num, int second_num);
|
||||
|
||||
#endif // CS480PREP
|
||||
28
Preparation/Makefile
Normal file
28
Preparation/Makefile
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
CC = gcc -Wall
|
||||
SOURCES = CS480_Prep.c
|
||||
OBJECTS = CS480_Prep.o
|
||||
|
||||
# Uses the template structure defined in the TypicalUtils folder
|
||||
|
||||
all: CS480_Prep
|
||||
|
||||
CS480_Prep: $(OBJECTS)
|
||||
$(CC) $(OBJECTS) -o CS480_Prep
|
||||
|
||||
CS480_Prep.o: CS480_Prep.c
|
||||
$(CC) -c CS480_Prep.c -o CS480_Prep.o
|
||||
|
||||
#GeneralUtility.o: GeneralUtility.c
|
||||
# $(CC) -c GeneralUtility.c -o GeneralUtility.o
|
||||
|
||||
clean:
|
||||
rm -f $(OBJECTS) CS480_Prep CS480_Prep.out
|
||||
|
||||
clean_objects:
|
||||
rm -f $(OBJECTS)
|
||||
|
||||
run:
|
||||
./CS480_Prep
|
||||
|
||||
run_win:
|
||||
CS480_Prep
|
||||
28
Preparation/Phase4/Makefile
Normal file
28
Preparation/Phase4/Makefile
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
CC = gcc -Wall
|
||||
SOURCES = Phase4_Prep.c
|
||||
OBJECTS = Phase4_Prep.o
|
||||
|
||||
# Uses the template structure defined in the TypicalUtils folder
|
||||
|
||||
all: Phase4_Prep
|
||||
|
||||
Phase4_Prep: $(OBJECTS)
|
||||
$(CC) $(OBJECTS) -o Phase4_Prep
|
||||
|
||||
Phase4_Prep.o: Phase4_Prep.c
|
||||
$(CC) -c Phase4_Prep.c -o Phase4_Prep.o
|
||||
|
||||
#GeneralUtility.o: GeneralUtility.c
|
||||
# $(CC) -c GeneralUtility.c -o GeneralUtility.o
|
||||
|
||||
clean:
|
||||
rm -f $(OBJECTS) Phase4_Prep Phase4_Prep.out
|
||||
|
||||
clean_objects:
|
||||
rm -f $(OBJECTS)
|
||||
|
||||
run:
|
||||
./Phase4_Prep
|
||||
|
||||
run_win:
|
||||
Phase4_Prep
|
||||
66
Preparation/Phase4/Phase4_Prep.c
Normal file
66
Preparation/Phase4/Phase4_Prep.c
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
// header files
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include "StandardConstants.h"
|
||||
|
||||
// constants
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
/*
|
||||
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 4: 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;
|
||||
}
|
||||
22
Preparation/Phase4/Phase4_Prep.h
Normal file
22
Preparation/Phase4/Phase4_Prep.h
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#ifndef CS480PREP
|
||||
#define CS480PREP
|
||||
|
||||
// header files
|
||||
|
||||
// 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 // CS480PREP
|
||||
73
Preparation/Phase4/StandardConstants.h
Normal file
73
Preparation/Phase4/StandardConstants.h
Normal 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
|
||||
28
Preparation/Phase5/Makefile
Normal file
28
Preparation/Phase5/Makefile
Normal 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
|
||||
32
Preparation/Phase5/Phase5_Prep.c
Normal file
32
Preparation/Phase5/Phase5_Prep.c
Normal 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;
|
||||
}
|
||||
11
Preparation/Phase5/Phase5_Prep.h
Normal file
11
Preparation/Phase5/Phase5_Prep.h
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#ifndef PHASE5PREP
|
||||
#define PHASE5PREP
|
||||
|
||||
// header files
|
||||
#include "StringUtils.h"
|
||||
|
||||
// data structures
|
||||
|
||||
// function prototypes
|
||||
|
||||
#endif // PHASE5PREP
|
||||
73
Preparation/Phase5/StandardConstants.h
Normal file
73
Preparation/Phase5/StandardConstants.h
Normal 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
|
||||
32
Preparation/Phase5/StringUtils.c
Normal file
32
Preparation/Phase5/StringUtils.c
Normal 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;
|
||||
}
|
||||
28
Preparation/Phase5/StringUtils.h
Normal file
28
Preparation/Phase5/StringUtils.h
Normal 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
|
||||
28
Preparation/Phase6/Makefile
Normal file
28
Preparation/Phase6/Makefile
Normal 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
|
||||
47
Preparation/Phase6/Phase6_Prep.c
Normal file
47
Preparation/Phase6/Phase6_Prep.c
Normal 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;
|
||||
}
|
||||
11
Preparation/Phase6/Phase6_Prep.h
Normal file
11
Preparation/Phase6/Phase6_Prep.h
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#ifndef PHASE6PREP
|
||||
#define PHASE6PREP
|
||||
|
||||
// header files
|
||||
#include "StringUtils.h"
|
||||
|
||||
// data structures
|
||||
|
||||
// function prototypes
|
||||
|
||||
#endif // PHASE6PREP
|
||||
73
Preparation/Phase6/StandardConstants.h
Normal file
73
Preparation/Phase6/StandardConstants.h
Normal 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
|
||||
163
Preparation/Phase6/StringUtils.c
Normal file
163
Preparation/Phase6/StringUtils.c
Normal 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
|
||||
*/
|
||||
28
Preparation/Phase6/StringUtils.h
Normal file
28
Preparation/Phase6/StringUtils.h
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue