Advertisement
cd62131

strcmp strncat

Dec 6th, 2018
452
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.62 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. int main(void) {
  4.   char s1[20], s2[20];
  5.   printf("1 番目の文字列(10 文字未満): ");
  6.   scanf("%9s", s1);
  7.   printf("2 番目の文字列(10 文字未満): ");
  8.   scanf("%9s", s2);
  9.   int cmp = strcmp(s1, s2);
  10.   char *p1, *p2;
  11.   if (cmp < 0) {
  12.     p1 = s2;
  13.     p2 = s1;
  14.   } else {
  15.     p1 = s1;
  16.     p2 = s2;
  17.   }
  18.   strncat(p1, p2, 10);
  19.   printf("大きい方の文字列に小さい方の文字列を連結すると、\n"
  20.          "%s\n"
  21.          "となります。\n",
  22.          p1);
  23.   printf("文字列全体の長さは %zd 文字です。", strlen(p1));
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement