uni

University stuff
git clone git://git.margiolis.net/uni.git
Log | Files | Refs | README | LICENSE

funcs_ex3.c (745B)


      1 #include <stdio.h>
      2 #include <string.h>
      3 
      4 /* 
      5  * Read 2 strings. If they are the same replace all a's with
      6  * b's, otherwise concatenate them using a third string.
      7  */
      8 
      9 int
     10 main(int argc, char *argv[])
     11 {
     12         char str1[64], str2[64], str3[64] = {0};
     13         int i = 0;
     14 
     15         printf("str1: ");
     16         fgets(str1, 64, stdin);
     17         printf("str2: ");
     18         fgets(str2, 64, stdin);
     19 
     20         if (!strcmp(str1, str2)) {
     21                 for (; i < strlen(str1); i++)
     22                         if (str1[i] == 'a')
     23                                 str1[i] = 'b';
     24         } else {
     25                 strcpy(str3, str1);
     26                 strcat(str3, str2);
     27         }
     28 
     29         printf("str1: %sstr2: %sstr3: %s\n", str1, str2, str3);
     30 
     31         return 0;
     32 }