9511_workbook

solved exercises from algorithms & programming I (9511) prof. Cardozo
Index Commits Files Refs README
guia03/ex07.c (504B)
   1 #include <stdio.h>
   2 #include <string.h>
   3 
   4 
   5 int main(void)
   6 {
   7     int i, s1_len, s2_len, cat_len;
   8 
   9     char s1[] = "Hello world!";
  10     char s2[] = "Hola mundo!";
  11 
  12     s1_len = strlen(s1);
  13     s2_len = strlen(s2);
  14 
  15     cat_len = ((s1_len + s2_len) + 1); //    One more for the '\0' byte;
  16     char cat[cat_len];
  17 
  18     for(i = 0; i <= cat_len; i++) {
  19         if (i < s1_len) {
  20             cat[i] = s1[i];
  21         } else if (i >= s1_len) {
  22             cat[i] = s2[i - s1_len];
  23         } else if (i == cat_len) {
  24             cat[i + 1] = '\0';
  25         }
  26     }
  27     printf("%s\n", cat);
  28     return 0;
  29 }