-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringFunctions.c
More file actions
37 lines (31 loc) · 1.43 KB
/
StringFunctions.c
File metadata and controls
37 lines (31 loc) · 1.43 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
#include <stdio.h>
#include <string.h>
int main()
{
char string1[] = "He";
char string2[] = "Zhengjie";
strlwr(string1); // converts a string to lowercase
strupr(string1); // converts a string to uppercase
strcat(string1, string2); // appends string2 to end of string1
strncat(string1, string2, 1); // appends the first n characters from string2 to string1
strcpy(string1, string2); // copies string2 to string1
strncpy(string1, string2, 4); // copies the first n characters of string2 to replace the first n characters of string1
strset(string1, '?'); // sets all characters of a string to a given character
strnset(string1, 'x', 1); // sets the first n characters of a string to a given character
strrev(string1); // reverses a string
int result = strlen(string1); // returns string length as int
int result = strcmp(string1, string2); // string compare all characters (returns 0 if equal or 1 if not equal)
int result = strncmp(string1, string2, 1); // string compare n characters
int result = strcmpi(string1, string1); // string compare all (ignore case)
int result = strnicmp(string1, string1, 1); // string compare n characters (ignore case)
printf("%s", string1);
printf("%d", result);
if(result == 0)
{
printf("These strings are the same");
}
else
{
printf("These strings are not the same");
}
}