C语言交换字符串

#include stdio.hint main() {char s1[] = TajMahal;char s2[] = Dazzling;

编程学习网为您整理以下代码实例,主要实现: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;
}
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐