fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include<string.h>
  4.  
  5. char* string_merge(char* tekst, char* tekst1)
  6. {
  7. int dlugosc,dlugosc1,krotszy;
  8. char* nowa;
  9.  
  10. dlugosc=strlen(tekst);
  11. dlugosc1=strlen(tekst1);
  12. //printf("\nDlugosc tekst=%d\nDlugosc tekst1=%d\n",dlugosc,dlugosc1);
  13. if(dlugosc<=dlugosc1) krotszy=dlugosc;
  14. else krotszy=dlugosc1;
  15. //printf("Krotszy ze stringow wynosi:%d\n",krotszy);
  16. nowa=(char*)calloc(2*krotszy,sizeof(char));
  17. for(int i=0; i<2*krotszy; ++i)
  18. {
  19. if(i%2==0) *(nowa+i)= *(tekst+(i/2));
  20. else *(nowa+i)=*(tekst1+(i-1)/2);
  21. }
  22. return nowa;
  23. }
  24.  
  25. int main()
  26. {
  27. //int ile_testow;
  28. char tekst[1000], tekst1[1000];
  29.  
  30. //printf("Podaj ile testow:");
  31. //scanf("%d",&ile_testow);
  32. //for(int i=0; i<ile_testow; ++i)
  33. //{
  34. printf("Podaj pierwszy ciag znakow:\n");
  35. gets(tekst);
  36. printf("Podaj drugi ciag znakow:\n");
  37. gets(tekst1);
  38. //}
  39. //printf("Podales:\n%s\n%s",tekst,tekst1);
  40. printf("%s",string_merge(tekst,tekst1));
  41. free(string_merge(tekst,tekst1));
  42. return 0;
  43. }
  44.  
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
Podaj pierwszy ciag znakow:
Podaj drugi ciag znakow:
p8�pU��;+