Browse Source

Implementation of function stringConcatenation() and creation of docs.txt to as a documentation for the functions.

remotes/origin/feature/customer-login
fdai7057 2 years ago
parent
commit
34f838204a
  1. 32
      src/StringManipulation.c
  2. 1
      src/StringManipulation.h
  3. 14
      src/docs.txt

32
src/StringManipulation.c

@ -1,5 +1,33 @@
#include "StringManipulation.h"
/*Code written by Julius Philipp Engel, fdai7057*/
char *stringConcatenation(char *string_1, char *string_2)
{
int lengthStringOne = strlen(string_1);
int lengthStringTwo = strlen(string_2);
if(lengthStringOne==0||lengthStringTwo==0){
printf("Empty strings are not allowed. Aborting.\n");
exit(-1);
//call error();
}
const int totalLength = lengthStringOne + lengthStringTwo + 1;
char *result = calloc(totalLength, sizeof(char));
int i,j;
for(i=0,j=0;i<totalLength;++i){
if(i<lengthStringOne){
*(result+i) = *(string_1+i);
}else{
*(result+i) = *(string_2+j);
++j;
}
}
*(result+i) = '\0';
return result;
}
char *to_string(int number)
{
if(number==0)
@ -28,10 +56,6 @@ char *to_string(int number)
char *generateCheckString(int customerID, char *customerPassword)
{
/*The purpose of this function is to generate a string that is needed when a user wants to login.
* This string is searched for in the customer-data file and if it is found, the login is successful.
* This function is needed when a new user is created because then it is written in the file for the first time.
* The format of the string is: [ID]=[PASSWORD]*/
char *IDString = to_string(customerID);
int IDLength = strlen(IDString);
int passwordLength = strlen(customerPassword);

1
src/StringManipulation.h

@ -1,5 +1,6 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
char *stringConcatenation(char *, char *);
char *to_string(int);
char *generateCheckString(int, char *);

14
src/docs.txt

@ -0,0 +1,14 @@
char *stringConcatenation(char string_1*, char string_2*):
This function takes two char pointers. In this function a new string is created. This new string is the concatenation of string_1 and string_2. The size of the new string is the length of string_1 plus the length of string_2 plus one for '\0'. This function is needed when creating an unique check string for a customer.
char *to_string(int number):
This function takes an integer variable as its argument. It returns an string that contains the digits of number. For example to_string(176) would return "176\0". This function is needed to write data in form of characters into the customer file.
char *generateCheckString(int customerID, char *password):
The purpose of this function is to generate a string that is needed when a user wants to login. This string is searched for in the customer-data file and if it is found, the login is successful. This function is needed when a new user is created because then it is written in the file for the first time.
The format of the returned string is [ID]=[PASSWORD].
For example generateCheckString(177,"tree") would return "177=tree\0".
Loading…
Cancel
Save