-
Notifications
You must be signed in to change notification settings - Fork 0
/
aux_strcmp.c
76 lines (68 loc) · 2.38 KB
/
aux_strcmp.c
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
/*
* File: aux_strcmp.c
*
* Auxiliar Source Code For GNU C Practice
*
* NAME
* strcmp, strncmp - compare two strings
*
* SYNOPSIS
* #include <string.h>
*
* int strcmp(const char *s1, const char *s2);
*
* int strncmp(const char *s1, const char *s2, size_t n);
*
* DESCRIPTION
* The strcmp() function compares the two strings s1 and s2.
* The locale is not taken into account (for a locale-aware comparison, see strcoll(3)).
* It returns an integer less than, equal to, or greater than zero if s1 is found,
* respectively, to be less than, to match, or be greater than s2.
*
* The strncmp() function is similar, except it compares only the first (at most) n bytes of s1 and s2.
*
* RETURN VALUE
* The strcmp() and strncmp() functions return an integer less than, equal to, or greater than zero
* if s1 (or the first n bytes thereof) is found, respectively, to be less than, to match, or be greater than s2.
*
*
* @Autor: Ezequiel Hernán Villanueva
* @Date: Thursday 29 of April of 2021
*/
// Inclusion of the Standard C Libraries needed
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
/*
* Main Function
* with counter of arguments
* and the pointer to an array of character
* that contain each argument
*/
int main(int argc, char *argv[])
{
// Initialization of variables
//char * test = "Beth,Charles,Danielle,Adam,Eric\n\0";
char * string1 = "Beth\0";
char * string2 = "Charles\0";
printf("\n");
printf("\nThe pointer to an array of character that is like a string of character \"string1\" have the value: %s \n", string1);
printf("\nThe pointer to an array of character that is like a string of character \"string2\" have the value: %s \n", string2);
// We Will try to order this alpabetically with the use of the function strcmp
printf("\nThe two array of characters alphabetically ordered are displayed below:\n");
if ( strcmp( string1, string2 ) > 0 )
{
printf("\n First string: %s\n", string2);
printf("\n Second string: %s\n", string1);
}
if ( strcmp( string1, string2 ) == 0 )
{
printf("\n String1 and String2 have the same initial character: %s %s \n", string1, string2);
}
if ( strcmp( string1, string2 ) < 0 )
{
printf("\n First string: %s\n", string1);
printf("\n Second string: %s\n", string2);
}
return 0; // Exit Status OK!
}