Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- /*allocates memory for concatenation of two input streams*/
- char *concatenation(const char *a, const char *b)
- {
- size_t len_a = strlen(a);
- size_t len_b = strlen(b);
- char *ret = (char *)malloc(len_a + len_b + 1);
- if(ret == NULL) {
- printf("Insufficient memory!\n");
- return 0;
- }
- for(int i = 0; i < len_a; i++) {
- ret[i] = a[i];
- }
- for(int i = len_a, j = 0; i < len_a + len_b; i++, j++) {
- ret[i] = b[j];
- }
- ret[len_a + len_b] = '\0';
- return 0;
- }
- int main(int argc, char *argv[])
- {
- if(argc != 3) {
- fprintf(stderr,"Invalid argument count!\n");
- return 1;
- }
- char *string = concatenation(argv[1], argv[2]);
- printf("%s\n", string);
- free(string);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement