Last active
January 8, 2018 22:46
-
-
Save aziis98/4479e6a4b6b4b8658480db51dbee029b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "stdio.h" | |
| int string_length(char * str) { | |
| if (*str == '\0') { | |
| return 0; | |
| } | |
| else { | |
| return string_length(str + 1) + 1; | |
| } | |
| } | |
| int main() { | |
| char str[1000] = { '\0' }; | |
| scanf("%s", &str); | |
| printf("%d\n", string_length(str)); | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| char* string_join(char *s1, int size1, char *s2, int size2) { | |
| char *r = malloc(sizeof(char) * (size1 + size2 + 1)); | |
| *(r + (size1 + size2)) = '\0'; | |
| for (int i = 0; i < size1; i++) { | |
| *(r + i) = *(s1 + i); | |
| } | |
| for (int i = size1; i < size1 + size2; i++) { | |
| *(r + i) = *(s2 + (i - size1)); | |
| } | |
| return r; | |
| } | |
| int main() { | |
| int m; | |
| scanf("%d", &m); | |
| char *s1 = malloc(sizeof(char) * (m + 1)); | |
| scanf("%s", s1); | |
| int n; | |
| scanf("%d", &n); | |
| char *s2 = malloc(sizeof(char) * (n + 1)); | |
| scanf("%s", s2); | |
| char *r = string_join(s1, m, s2, n); | |
| printf("%s", r); | |
| return 0; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment