-
Notifications
You must be signed in to change notification settings - Fork 0
/
day-strs.c
44 lines (33 loc) · 1.04 KB
/
day-strs.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
https://powcoder.com
代写代考加微信 powcoder
Assignment Project Exam Help
Add WeChat powcoder
https://powcoder.com
代写代考加微信 powcoder
Assignment Project Exam Help
Add WeChat powcoder
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int main() {
// Difference between strings and characters
// Initializing the array s2 with a string that contains null termination character
char s1[2] = "\0"; // 1
// Trying to use a char to initialize an array => compiler error
//char s2[2] = '\0'; // 2
char s3[3] = "\\0"; // 3
printf("%s\n", s3); // 4
// static initialization
char first[] = "Monday"; // {'M', 'o', 'n', ..}
char *second = "Tuesday";
char *third = malloc(strlen("Wednesday") + 1);
strncpy(third, "Wednesday", strlen("Wednesday") + 1);
//third = "Wednesday"; // third now points to string literal and is memory leak
printf("%s ", first);
sleep(1);
printf("%s ", second);
sleep(1);
printf("%s\n", third);
return 0;
}