交换两个字符串内容

来源:互联网 发布:oracle数据库存年份 编辑:程序博客网 时间:2024/05/17 23:10
#include <stdio.h>static void swap_string(char **p1, char **p2){char *tmp = NULL;tmp = *p1;*p1 = *p2;*p2 = tmp;}static void swap_strings(char *src[][2],unsigned int row){unsigned int i = 0;for (i = 0; i < row; ++i){swap_string(*(src + i), *(src+ i) + 1);}}static void print_strings(char *src[][2],unsigned int row){unsigned int i = 0;for (i = 0; i < row; ++i){printf("Case %d:\n%s\n%s\n\n", i+1, src[i][0], src[i][1]);}}int main(void){char* strSrc[][2] = {{"I am a good teacher.","Hello good morning ."},{"ABCDEF","123"},{"1234567890","abcdef"},{"测试","ceshi"}  };unsigned int row = 0;row = sizeof(strSrc)/sizeof(strSrc[0]);swap_strings(strSrc,row);print_strings(strSrc,row);return 0;}

0 0
原创粉丝点击