帮助完成一下行列转换的函数吧!谢谢!
各位大咖,小弟是学VB的,但是有一道C语言的题需要完成,麻烦各位大哥给写一下,谢谢了!题的回答对我很重要,麻烦打架了!我实在是不懂C.万分感谢!具体如下:
应用题目:编写 R2C 函数,将列序数据转换为行序数据.
主程序如下:
/*fff.c */
#include <stdio.h>
#include <stdlib.h>
/*
逐列存储的wc_t数组转换成逐行储输的p_d数组.
需转换行数Irow,需转换列数Icol.
pr_d指向转换后按行存储的数组.
转换输出:0成功 ,1失败.
*/
int R2C(const wc_t *p_d,int lrow,int lcol,wc_t **pr_d)
{
return 1;
}
void main(void)
{
FILE *fpInput;
wc_t *p_d = NULL;
wc_t *p_dnew = NULL;
int lrow;
int lcol;
int istatus;
int i, j;
/*读文件*/
fpInput = fopen("C:\\ddd.dat", "rb");
irow = 50;
icol = 12;
pdata = (wc_t*)malloc(lrow*lcol*sizeof(wc_t)); istatus = fread(pdata, sizeof(wc_t), lrow*lcol, fpInput); if (istatus != lrow*lcol)
{
printf("Read file error!\n"); return;
}
Fclose(fpInput);
/*调用R2C函数*/
istatus = R2C(pdata, lrow, lcol, &p_dnew); if (istatus==1)
{
printf("转换错误!\n"); return;
}
/*转换后*/
for (i = 0; i < lrow; i++)
{
printf("%02d-->", i); for (j = 0; j < lcol; j++)
{
printf("%c", *(p_dnew + i*lcol + j));
}
printf("\n");
}
free(p_d);
free(p_dnew);
getchar();
}
请帮助编写R2C 函数.谢谢!