请编写函数fun,该函数的功能是:将M行N列的二维数组中的字符数据,按列的顺序依次放到一个字符串中

/*请编写函数fun,该函数的功能是:将M行N列的二维数组中的字符数据,按列的顺序依次放到一个字符串中。 */

#include <stdio.h>
#define M 3
#define N 2
void fun(char buff[][N],char *buf,int m, int n)
{
    int k=0;
    for(int j=0;j<m;j++)
    {
        for(int i=0;i<n;i++)
        {
            buf[k++]=buff[j][i];
        }
    }
}
int main()
{
    char buff[M][N];
    char buf[100];
    for(int i=0;i<M;i++)
    {
        for(int j=0;j<N;j++)
        {
            printf("please enter buff[%d][%d] element\n",i+1,j+1);
            scanf("%s",&buff[i][j]);
        }
    }
    fun(buff,buf,M,N);
    printf("%s\n",buf);
    return 0;
}

posted on 2024-06-25 23:33  wessf  阅读(42)  评论(0)    收藏  举报