Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. char *concat(char **s, int n)
  6. {
  7. int length = 0, i;
  8. for (i = 0; i < n; i ++)
  9. length += strlen(s[i]);
  10. length ++;
  11. char *string = (char*)malloc(length);
  12. strcpy(string, " ");
  13.  
  14. for (i = 0; i < n; i ++)
  15. {
  16. strcat(string, s[i]);
  17. }
  18. return string;
  19. }
  20.  
  21. int main()
  22. {
  23. char *string[10000];
  24. int i, n;
  25.  
  26. for (i = 0; i < 10000; i ++)
  27. string[i] = (char*)malloc(50);
  28.  
  29. scanf("%d", &n);
  30. for (i = 0; i < n; i ++)
  31. gets(string[i]);
  32. char *t_string = concat(string, n);
  33. puts(t_string);
  34.  
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement