-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathssFunctions1.c
More file actions
123 lines (110 loc) · 2.52 KB
/
ssFunctions1.c
File metadata and controls
123 lines (110 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include "simpleshellmain.h"
/**
* copyString - copies a string from source to destination
* @destination: the destination string
* @source: the source string
*
* Description: This function copies the string pointed by `src` to the
* string pointed by `dest`, including the null terminator.
*
* Return: The pointer to the destination string (`dest`)!
*/
char *copyString(char *destination, char *source)
{
int index;
int length;
length = stringLength(source);
for (index = 0; index <= length; index++)
{
destination[index] = source[index];
}
return (destination);
}
/**
* stringlength - Calculate the length of a string
* @str: The input string
*
* Description: This function calculates the length of the given string.
*
* Return: The length of the string.
*/
int stringLength(char *str)
{
int length;
length = 0;
while (str[length] != '\0')
{
length++;
}
return (length);
}
/**
* stringCompare - compares two strings
* to find out if they are exactly the same
* @userInput: user input supplied to search for
* @compareString: string to compare against
* @inputLength: length of userInput
*
* Description: This function compares
* two strings and returns 1 if they are equal,
* -1 if they are not, and 0 if their lengths are different.
*
* Return: Returns 1 if the strings are identical,
* -1 if they differ, and 0 if their lengths are not the same
*/
int stringCompare(char *userInput, char *compareString, unsigned int inputLength)
{
unsigned int compareLength;
unsigned int i;
compareLength = stringLength(compareString);
if (compareLength != inputLength)
{
return (-1);
}
i = 0;
while (userInput[i] != '\0' && compareString[i] != '\0')
{
if (userInput[i] != compareString[i])
{
return (1);
}
i++;
}
return (0);
}
/**
* stringCompareN - compare two strings up to a specified length
* @str1: first string
* @str2: second string
* @length: number of characters to compare
*
* Description: This function compares two strings up to a specified length.
*
* Return: Returns 1 if the strings are identical, and -1 otherwise.
*/
int stringCompareN(char *str1, char *str2, unsigned int length)
{
unsigned int i;
i = 0;
while (i < length)
{
if (str1[i] != str2[i])
{
return (-1);
}
i++;
}
return (1);
}
/**
* weOut_Deuces - Exits the shell program.
*
* Description: This function is responsible for terminating the shell program
* and returning an exit status of -1.
* Return: Returns -1 to indicate shell exit.
*
*/
int weOut_Deuces(void)
{
return (-1);
}