Browse Source

Implementation of function everyCharacterIsDigit().

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

18
src/stringManipulation.c

@ -67,16 +67,32 @@ 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)
{
if(everyCharacterIsDigit(ID)){
unsigned int result = 0;
int IDLength = strlen(ID);
for(int i=0, j = IDLength - 1;i<IDLength;++i,--j){
result += (*(ID+j) - '0') * power(10,i);
}
return result;
} else {
return 0;
}
}
char *generateCheckString(unsigned int customerID, char *customerPassword)
{

3
src/stringManipulation.h

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