C语言交换字符串

#include <stdio.h>

int main() {
   char s1[] = "TajMahal";     
   char s2[] = "Dazzling";     
   char ch;

   int index = 0;

   //Character by Character approach

   printf("Before Swapping - /n");
   printf("Value of s1 - %s /n", s1);
   printf("Value of s2 - %s /n", s2);

   while(s1[index] != '/0') {
      ch = s1[index];
      s1[index] = s2[index];
      s2[index] = ch;
      index++;
   }

   printf("After Swapping - /n");
   printf("Value of s1 - %s /n", s1);
   printf("Value of s2 - %s /n", s2);

   return 0;
}

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/265352.html

(0)
上一篇 2022年6月7日
下一篇 2022年6月7日

相关推荐

发表回复

登录后才能评论