From ac04c8d2449dbb4010cd5290bfec72db8636677e Mon Sep 17 00:00:00 2001 From: fdai7057 Date: Sat, 4 Feb 2023 18:05:46 +0100 Subject: [PATCH] Implementation of function stod() and rename file stringManipulation.{c,h} to helperFunctions.{c,h} because the functions implemented there address different problems and not only string-specific problems. --- build-script.sh | 3 ++- project.yml | 2 +- src/createCustomer.h | 2 +- ...stringManipulation.c => helperFunctions.c} | 23 ++++++++++++++++++- ...stringManipulation.h => helperFunctions.h} | 1 + src/loginCustomer.h | 1 - test/test_CreateCustomer.c | 2 +- test/test_LoginCustomer.c | 2 +- ...gManipulation.c => test_helperFunctions.c} | 2 +- 9 files changed, 30 insertions(+), 8 deletions(-) rename src/{stringManipulation.c => helperFunctions.c} (86%) rename src/{stringManipulation.h => helperFunctions.h} (95%) rename test/{test_StringManipulation.c => test_helperFunctions.c} (99%) diff --git a/build-script.sh b/build-script.sh index fd72393..34cdd7c 100755 --- a/build-script.sh +++ b/build-script.sh @@ -1,7 +1,8 @@ clear ceedling test:all +rm -r build cd src/ -gcc stringManipulation.c error.c loginCustomer.c createCustomer.c mainMenu.c program.c -lm -o program.out +gcc helperFunctions.c error.c loginCustomer.c createCustomer.c mainMenu.c program.c -lm -o program.out ./program.out rm program.out cd .. diff --git a/project.yml b/project.yml index 91cbc02..0474ba1 100644 --- a/project.yml +++ b/project.yml @@ -36,7 +36,7 @@ :source: - src/createCustomer.* - src/customerLogin.* - - src/stringManipulation.* + - src/helperFunctions.* - src/error.* :support: - test/support diff --git a/src/createCustomer.h b/src/createCustomer.h index 112d2ac..1b87870 100644 --- a/src/createCustomer.h +++ b/src/createCustomer.h @@ -5,7 +5,7 @@ #include #include #include "customerProperties.h" -#include "stringManipulation.h" +#include "helperFunctions.h" #include "error.h" int generateID(); void collectCustomerProperties(); diff --git a/src/stringManipulation.c b/src/helperFunctions.c similarity index 86% rename from src/stringManipulation.c rename to src/helperFunctions.c index 29111f5..28ec136 100644 --- a/src/stringManipulation.c +++ b/src/helperFunctions.c @@ -1,4 +1,4 @@ -#include "stringManipulation.h" +#include "helperFunctions.h" /*Code written by Julius Philipp Engel, fdai7057*/ char *stringConcatenation(char *string_1, char *string_2) @@ -116,3 +116,24 @@ char *generateCheckString(unsigned int customerID, char *customerPassword) *(checkString+checkStringLength) = '\0'; return checkString; } + +double stod(char *s) +{ + double result, power; + int i=0, sign; + sign = (*(s) == '-') ? -1 : 1; + if(*(s)=='+'||*(s)=='-'){ + ++i; + } + for(result = 0.0; *(s+i)!='.';++i){ + result = 10.0 * result + (*(s+i) - '0'); + } + if(*(s+i)=='.'){ + ++i; + } + for(power = 1.0;*(s+i)!='\0';++i){ + result = 10.0 * result + (*(s+i)- '0'); + power *= 10.0; + } + return sign * result / power; +} diff --git a/src/stringManipulation.h b/src/helperFunctions.h similarity index 95% rename from src/stringManipulation.h rename to src/helperFunctions.h index 13bd217..ef5383b 100644 --- a/src/stringManipulation.h +++ b/src/helperFunctions.h @@ -11,4 +11,5 @@ unsigned int toUnsignedInteger(char *); unsigned int power(unsigned int, unsigned int); bool everyCharacterIsDigit(char *); bool isLetterOfAlphabet(char *); +double stod(char *); #endif diff --git a/src/loginCustomer.h b/src/loginCustomer.h index 9e5f1b0..251e0d9 100644 --- a/src/loginCustomer.h +++ b/src/loginCustomer.h @@ -4,7 +4,6 @@ #include #include #include -/*#include "stringManipulation.h"*/ #include "createCustomer.h" #include "error.h" #define MAX_LOGIN_ATTEMPTS 3 diff --git a/test/test_CreateCustomer.c b/test/test_CreateCustomer.c index 85122a7..4b48a74 100644 --- a/test/test_CreateCustomer.c +++ b/test/test_CreateCustomer.c @@ -1,7 +1,7 @@ #include #include #include -#include "../src/stringManipulation.c" +#include "../src/helperFunctions.c" #include "../src/error.c" #include "../src/createCustomer.c" diff --git a/test/test_LoginCustomer.c b/test/test_LoginCustomer.c index a293a0d..61a7a75 100644 --- a/test/test_LoginCustomer.c +++ b/test/test_LoginCustomer.c @@ -1,6 +1,6 @@ #include #include "../src/loginCustomer.c" -#include "../src/stringManipulation.c" +#include "../src/helperFunctions.c" #include "../src/error.c" void setUp(){}; void tearDown(){}; diff --git a/test/test_StringManipulation.c b/test/test_helperFunctions.c similarity index 99% rename from test/test_StringManipulation.c rename to test/test_helperFunctions.c index efbd1b2..57157b8 100644 --- a/test/test_StringManipulation.c +++ b/test/test_helperFunctions.c @@ -2,7 +2,7 @@ #include #include #include -#include "../src/stringManipulation.c" +#include "../src/helperFunctions.c" void test_isLetterOfAlphabet()