Browse Source

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.

remotes/origin/development
fdai7057 2 years ago
parent
commit
ac04c8d244
  1. 3
      build-script.sh
  2. 2
      project.yml
  3. 2
      src/createCustomer.h
  4. 23
      src/helperFunctions.c
  5. 1
      src/helperFunctions.h
  6. 1
      src/loginCustomer.h
  7. 2
      test/test_CreateCustomer.c
  8. 2
      test/test_LoginCustomer.c
  9. 2
      test/test_helperFunctions.c

3
build-script.sh

@ -1,7 +1,8 @@
clear clear
ceedling test:all ceedling test:all
rm -r build
cd src/ 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 ./program.out
rm program.out rm program.out
cd .. cd ..

2
project.yml

@ -36,7 +36,7 @@
:source: :source:
- src/createCustomer.* - src/createCustomer.*
- src/customerLogin.* - src/customerLogin.*
- src/stringManipulation.*
- src/helperFunctions.*
- src/error.* - src/error.*
:support: :support:
- test/support - test/support

2
src/createCustomer.h

@ -5,7 +5,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <time.h> #include <time.h>
#include "customerProperties.h" #include "customerProperties.h"
#include "stringManipulation.h"
#include "helperFunctions.h"
#include "error.h" #include "error.h"
int generateID(); int generateID();
void collectCustomerProperties(); void collectCustomerProperties();

23
src/stringManipulation.c → src/helperFunctions.c

@ -1,4 +1,4 @@
#include "stringManipulation.h"
#include "helperFunctions.h"
/*Code written by Julius Philipp Engel, fdai7057*/ /*Code written by Julius Philipp Engel, fdai7057*/
char *stringConcatenation(char *string_1, char *string_2) char *stringConcatenation(char *string_1, char *string_2)
@ -116,3 +116,24 @@ char *generateCheckString(unsigned int customerID, char *customerPassword)
*(checkString+checkStringLength) = '\0'; *(checkString+checkStringLength) = '\0';
return checkString; 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;
}

1
src/stringManipulation.h → src/helperFunctions.h

@ -11,4 +11,5 @@ unsigned int toUnsignedInteger(char *);
unsigned int power(unsigned int, unsigned int); unsigned int power(unsigned int, unsigned int);
bool everyCharacterIsDigit(char *); bool everyCharacterIsDigit(char *);
bool isLetterOfAlphabet(char *); bool isLetterOfAlphabet(char *);
double stod(char *);
#endif #endif

1
src/loginCustomer.h

@ -4,7 +4,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h> #include <stdbool.h>
#include <string.h> #include <string.h>
/*#include "stringManipulation.h"*/
#include "createCustomer.h" #include "createCustomer.h"
#include "error.h" #include "error.h"
#define MAX_LOGIN_ATTEMPTS 3 #define MAX_LOGIN_ATTEMPTS 3

2
test/test_CreateCustomer.c

@ -1,7 +1,7 @@
#include <unity.h> #include <unity.h>
#include <limits.h> #include <limits.h>
#include <math.h> #include <math.h>
#include "../src/stringManipulation.c"
#include "../src/helperFunctions.c"
#include "../src/error.c" #include "../src/error.c"
#include "../src/createCustomer.c" #include "../src/createCustomer.c"

2
test/test_LoginCustomer.c

@ -1,6 +1,6 @@
#include <unity.h> #include <unity.h>
#include "../src/loginCustomer.c" #include "../src/loginCustomer.c"
#include "../src/stringManipulation.c"
#include "../src/helperFunctions.c"
#include "../src/error.c" #include "../src/error.c"
void setUp(){}; void setUp(){};
void tearDown(){}; void tearDown(){};

2
test/test_StringManipulation.c → test/test_helperFunctions.c

@ -2,7 +2,7 @@
#include <time.h> #include <time.h>
#include <string.h> #include <string.h>
#include <unity.h> #include <unity.h>
#include "../src/stringManipulation.c"
#include "../src/helperFunctions.c"
void test_isLetterOfAlphabet() void test_isLetterOfAlphabet()
Loading…
Cancel
Save