-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path25_string.c
More file actions
57 lines (45 loc) · 1.5 KB
/
25_string.c
File metadata and controls
57 lines (45 loc) · 1.5 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
int main()
{
// char word = 's';
// printf("%c\n", word);
//
// char greeting[] = "hello world";
// printf("%s\n", greeting);
// printf("%c\n", greeting[4]);
// greeting[5] = '_';
// printf("%s\n", greeting);
//
// int length = sizeof(greeting)/ sizeof(char);
// //int length = sizeof(greeting);
// printf("length of word: %d\n", length);
//
// int i;
// for(i = 0; i<length; i++)
// {
// printf("%c\n", greeting[i]);
// }
// **********************************************
// char greeting_02[] = "hello";
//
// printf("way one to fetch len: %d\n", sizeof(greeting_02)/ sizeof(char));
// printf("way two to fetch len: %lu\n", sizeof(greeting_02));
// printf("way three to fetch len: %d\n", strlen(greeting_02));
// printf("way one to fetch len: %d\n", sizeof(greeting_02)/ sizeof(greeting_02[0]));
// **********************************************
char txt_01[] = "hey,";
char txt_02[] = " i'm more";
strcat(txt_01, txt_02);
printf("variable txt_01 after concatination string: %s\n", txt_01);
// **********************************************
char res[] = "";
strcpy(res, txt_01);
printf("variable res(copy function):%s\n", res);
// *********************************************
char str1[] = "Hello";
char str2[] = "Hello";
char str3[] = "Hi";
// Compare str1 and str2, and print the result
printf("%d\n", strcmp(str1, str2)); // Returns 0 (the strings are equal)
// Compare str1 and str3, and print the result
printf("%d\n", strcmp(str1, str3)); // Returns -4 (the strings are not equal)
}