Browse Source

Implementation of function power().

remotes/origin/development
fdai7057 2 years ago
parent
commit
854366fd97
  1. 1
      src/createCustomer.c
  2. 1
      src/loginCustomer.c
  3. 6
      src/stringManipulation.c
  4. 2
      src/stringManipulation.h

1
src/createCustomer.c

@ -21,7 +21,6 @@ void collectCustomerProperties()
bool inputTooLong = false;
printf("To create a new user, enter the information required below.\n");
printf("Enter forename (max. 15 letters):\n");
userInput = getchar();
while(letterCounter<letterMaximum && (userInput=getchar())!='\n'){
*(instance.forename+letterCounter) = userInput;
++letterCounter;

1
src/loginCustomer.c

@ -61,7 +61,6 @@ bool loginCustomer(customer_t *c)
bool foundCustomerEntryInFile = false;
unsigned int IDAsNumber = toUnsignedInteger(c->IDAsString);
char *searchForThisString = generateCheckString(IDAsNumber,c->password);
printf("Searching for: %s\n", searchForThisString);
char *lineFromCustomerFile = calloc(40,sizeof(char));
FILE *readCustomerFile = fopen("CustomerData.txt", "r");
if(readCustomerFile==NULL){

6
src/stringManipulation.c

@ -54,10 +54,10 @@ char *to_string(int number)
}
}
unsigned int powerOfTen(unsigned int n){
unsigned int power(unsigned int b, unsigned int n){
unsigned int result = 1, ctr = 0;
while(ctr<n){
result *= 10;
result *= b;
++ctr;
}
return result;
@ -68,7 +68,7 @@ unsigned int toUnsignedInteger(char *ID)
unsigned int result = 0;
int IDLength = strlen(ID);
for(int i=0, j = IDLength - 1;i<IDLength;++i,--j){
result += (*(ID+j) - '0') * powerOfTen(i);
result += (*(ID+j) - '0') * power(10,i);
}
return result;
}

2
src/stringManipulation.h

@ -6,4 +6,4 @@ char *stringConcatenation(char *, char *);
char *to_string(int);
char *generateCheckString(unsigned int, char *);
unsigned int toUnsignedInteger(char *);
unsigned int powerOfTen(unsigned int);
unsigned int power(unsigned int, unsigned int);
Loading…
Cancel
Save