Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*********************************************************************
- Создать две строки — на стеке (char example[size]) и в куче (malloc()). Записать в них что-нибудь (strcpy()). Создать третью строку достаточной длины (любым из способов) и записать в неё результат соединения первых двух (strcat()). Вывести на экран все три строки, указав их длину (strlen()).
- */
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #define size 128u
- int main()
- {
- char str[size];
- char* str2 = (char*)malloc(size * sizeof(char));
- char* str3 = (char*)malloc((size * 2) * sizeof(char));
- strcpy_s(str, size, "Prince of");
- strcpy_s(str2, size, " Persia");
- strcpy_s(str3, size, str);
- strcat_s(str3, size, str2);
- printf("str = \"%s\" (len = %d)\n", str, strlen(str));
- printf("str2 = \"%s\" (len = %d)\n", str2, strlen(str2));
- printf("str3 = \"%s\" (len = %d)\n", str3, strlen(str3));
- free(str2);
- free(str3);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement