CS计算机代考程序代写 int main()

int main()
char first[7] = ¡°Monday¡±;
char *second = ¡°Tuesday¡±;
char *third = malloc(10);
strncpy(third, ¡°Wednesday¡±, 10);
Youshould beable toexplain why the follow is wrong
third Wednesday char *string_list[3];
string_list[0] = first;
string_list[1] = second;
string_list[2] = third;
p
CSC209H Worksheet: Strings
1. Write a program that declares 3 strings. The first named first should be set to the value “Monday”, and be stored on the stack frame for main. second should be a string literal with the value “Tuesday”. third should have value “Wednesday” and be on the heap. The pointers for second and third will be in stack frame for main.
Then beside it, draw the memory model for your program after all three strings have been created. Using the starter code posted on the course website, type your program into your computer (or work with a friend on their computer.)
Section
Read-only
Address
0x100 0x104
0x108
0x10c
0x110
Value
Label
Heap
We d n es da
stack frame for main0x450 0x454 0x458 0x45c 0x460 0x464 0x468 0x46c 0x470 0x474 0x478 0x47c
MO n4 first
ay own 10108
923C
TIE
230
0 114
sI .
da
11
e 0 116 1
0x23c 0x240
0x244
0x248
0x24c
.
.
day 10
KE
.
0 450
¦Ì
0
second third

CSC209H Worksheet: Strings
2. Add to your program so that it declares an array string list of 3 pointers to char and point the elements to first, second, and third, respectively. So now you have an array of strings. Where is the memory allocated for this array? Add to your memory model diagram as well. Once you have this complete, show it to a TA or the professor and ask for the next handout which has the solutions to questions 1 and 2 and a place to answer question 3.
3. Now, add a new function build month list that allocates, initializes and returns an array of 3 strings with the values “January”, “February”, and “March”. All the strings need to be mutable, so that the main function can shorten them. Remember to uncomment the code in main that tests that build month list is testable.
4. If you are finished (or if you can¡¯t figure out why your code isn¡¯t working), draw a memory diagram illustrating your program at the moment just before build month list returns.
see the provided solution code

#include
#include
#include
// Part 3: Implement build_month_list.
CSC209H Worksheet: Strings
int main() {
// Part 1: Declare and initialize first, second, and third.
char first[7] = “Monday”;
char *second = “Tuesday”;
char *third = malloc(10 * sizeof(char));
//third = “Wednesday”; <- DOES NOT WORK make sure you understand why! strcpy(third,"Wednesday"); printf("%s %s %s\n", first, second, third); // Part 2: Declare and initialize string_list. char *string_list[3]; string_list[0] = first; string_list[1] = second; string_list[2] = third; printf("%s %s %s\n", string_list[0], string_list[1], string_list[2]); char **months = build_month_list(); for(int i = 0; i < 3; i++) { printf("%s ", months[i]); } printf("\n"); for(int i = 0; i < 3; i++) { months[i][3] = ¡¯\0¡¯; printf("%s ", months[i]); } printf("\n"); return 0; }