From 2ad433c776761ebcbe178d60d9ce341831bdf286 Mon Sep 17 00:00:00 2001 From: fdai7057 Date: Thu, 26 Jan 2023 11:55:46 +0100 Subject: [PATCH] Implementation of function stringConcatenation() and creation of docs.txt to as a documentation for the functions. --- src/StringManipulation.c | 32 ++++++++++++++++++++++++++++---- src/StringManipulation.h | 1 + src/docs.txt | 14 ++++++++++++++ 3 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 src/docs.txt diff --git a/src/StringManipulation.c b/src/StringManipulation.c index cd2ad2c..7ac306e 100644 --- a/src/StringManipulation.c +++ b/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 #include #include +char *stringConcatenation(char *, char *); char *to_string(int); char *generateCheckString(int, char *); diff --git a/src/docs.txt b/src/docs.txt new file mode 100644 index 0000000..c76de12 --- /dev/null +++ b/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".