Concatena Stringhe

    0

    2

    The code creates a new string by appending the first string to the second string. The size of the new string is the sum of the lengths of the two strings.

    Shortcut: conca

    char* my_strcat1(char *s1, char *s2) {
      int lun1=strlen(s1);
      int lun2=strlen(s2);
      char *sf;
      sf = malloc((lun1+lun2+1)*sizeof(char));
      
      for(int i=0; i<lun1;i++) {
        sf[i] = s1[i];
      }
      
      for(int i=0; i<lun2;i++) {
        sf[i+lun1] = s2[i];
      }
      sf[lun1+lun2] = '\0';
      return sf;
    }
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.