Browse Source

Implementation of function everyCharacterIsDigit().

remotes/origin/development
fdai7057 2 years ago
parent
commit
fa12fdef2a
  1. 20
      src/stringManipulation.c
  2. 3
      src/stringManipulation.h

20
src/stringManipulation.c

@ -67,17 +67,33 @@ unsigned int power(unsigned int base, unsigned int exponent){
} }
} }
bool everyCharacterIsDigit(char *string)
{
bool onlyDigits = true;
for(int i=0;*(string+i)!='\0';++i){
if(*(string+i)<'0'||*(string+i)>'9'){
onlyDigits = false;
break;
}
}
return onlyDigits;
}
unsigned int toUnsignedInteger(char *ID) unsigned int toUnsignedInteger(char *ID)
{ {
if(everyCharacterIsDigit(ID)){
unsigned int result = 0; unsigned int result = 0;
int IDLength = strlen(ID); int IDLength = strlen(ID);
for(int i=0, j = IDLength - 1;i<IDLength;++i,--j){ for(int i=0, j = IDLength - 1;i<IDLength;++i,--j){
result += (*(ID+j) - '0') * power(10,i); result += (*(ID+j) - '0') * power(10,i);
} }
return result;
return result;
} else {
return 0;
}
} }
char *generateCheckString(unsigned int customerID, char *customerPassword) char *generateCheckString(unsigned int customerID, char *customerPassword)
{ {
char *IDString = to_string(customerID); char *IDString = to_string(customerID);

3
src/stringManipulation.h

@ -1,9 +1,10 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <math.h>
#include <stdbool.h>
char *stringConcatenation(char *, char *); char *stringConcatenation(char *, char *);
char *to_string(int); char *to_string(int);
char *generateCheckString(unsigned int, char *); char *generateCheckString(unsigned int, char *);
unsigned int toUnsignedInteger(char *); unsigned int toUnsignedInteger(char *);
unsigned int power(unsigned int, unsigned int); unsigned int power(unsigned int, unsigned int);
bool everyCharacterIsDigit(char *);
Loading…
Cancel
Save