bsc

Comprehensive codebase and cou...
Log | Files | Refs | Activity | README | LICENSE

root / semester_1 / tuition-c / P067.c

P067.c (609B)


      1 /* Write a program using function which concatenates two string s1 and s2 in to a third string */
      2 
      3 #include <stdio.h>
      4 
      5 void string_concat(char *s3, char s1[], char s2[])
      6 {
      7     int l1, l2, i, j, k;
      8     i = j = k = 0;
      9     l1 = strlen(s1);
     10     l2 = strlen(s2);
     11     s3 = (char *)malloc((l1 + l2 + 1) * sizeof(char));
     12     while (s1[i] != '\0')
     13     {
     14         s3[k++] = s1[i++];
     15     }
     16     while (s2[j] != '\0')
     17     {
     18         s3[k++] = s2[j++];
     19     }
     20     s3[k] = '\0';
     21     puts(s3);
     22 }
     23 
     24 int main()
     25 {
     26     char s1[] = "JAVA";
     27     char s2[] = "PYTHON";
     28     char *s3 = NULL;
     29     string_concat(s3, s1, s2);
     30     return 0;
     31 }
© notamitgamer • Site Built: 2026-09-05 01:53:16 UTC • git-mirror commit: c170d72 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror