Advertisement
Guest User

ghfjh

a guest
Mar 17th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. int len=0;
  5. char *arr;
  6. int mystrlen(char *s);
  7. int h;
  8. char **warr;
  9. char *my_strcat(char *str_one, char *str_two){
  10. while (*str_one){
  11. str_one++;
  12. }
  13. while(*str_two){
  14. *str_one=*str_two;
  15. str_one++;
  16. str_two++;
  17. }
  18. *str_one = '\0';
  19. return str_one;
  20. }
  21. char *links(char **C, int M){
  22.  
  23. for(int j=0;j<=(M-1); j=(j+1)){
  24. len=(len+(((int)mystrlen(C[j])))+ 1);
  25. }
  26. arr=(char *)calloc((len),sizeof(char));
  27. if(0==arr){
  28. printf("Error");
  29. return 1;
  30. }
  31. arr[0]='\0';
  32. for(int k=0; k<=(M-1); k=(k+1)){
  33. strncat(arr,C[k],((mystrlen(C[k]))+1));
  34. }
  35. return arr;
  36. }
  37.  
  38. int main(void){
  39. scanf("%d ", &h);
  40. char *w=0;
  41. warr=malloc(sizeof(char *) *h);
  42. if(0==warr){
  43. printf("Error");
  44. return 1;
  45. }
  46. for(int j=0; j<=(h-1); j=(j+1)){
  47. warr[j]= malloc(100*sizeof(char));
  48. if(warr[j] == 0){
  49. printf("Error ");
  50. return 1;
  51. }
  52. gets(warr[j]);
  53. }
  54. w=links(warr, h);
  55. printf("%s", w);
  56. printf("\n");
  57.  
  58. for(int k=0; k<=(h-1); k=(k+1)){
  59. free(warr[k]);
  60. }
  61. free(warr);
  62. free(w);
  63. return 0;
  64. }
  65. int mystrlen(char *B){
  66. int m;
  67. for(m=0; B[m]; m++);
  68. return m;
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement