为什么从文件中读取的数据保存到另一个文件中就成乱码了 ?
PloyIn.txt 中的数据为:3 1 0 1 1 1 2
3 2 0 3 2 7 9
3 90 0 78 4 8 8
只输出一项
PloyOut.txt中数据为
3 0.000000 -1869574000
请大神帮忙看看哪里出问题了 ?
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
float coef; /*系数*/
int expn; /*指数*/
}ElemType;
typedef struct LNode
{
ElemType data;
struct LNode *pNext;
}LNode, *Ploynomial;
void menu ()
{
printf ("************************************************************\n");
printf ("------------------------------------------------------------\n");
printf ("\t\t 多项式运算环境\t\t\n");
printf ("------------------------------------------------------------\n");
printf ("\t\t (1): 创建多项式\t\n");
printf ("\t\t (2): 打印多项式\t\n");
printf ("\t\t (3): 多项式相加\t\n");
printf ("\t\t (4): 多项式相减\t\n");
printf ("\t\t (5): 多项式相乘\t\n");
printf ("\t\t (6): 多项式混合运算\t\n");
printf ("\t\t (7): 退出多项式\t\n");
printf ("************************************************************\n");
printf ("请输入你的选择: ");
}
void InitList (Ploynomial Ployn)
{
Ployn = (Ploynomial) malloc (sizeof (LNode));
Ployn -> pNext == NULL;
}
int ReadPloyn1(int n)
{
FILE *fp;
if ((fp = fopen("PloyIn.txt", "r")) == NULL)
{
printf ("错误!");
exit(0);
}
fscanf (fp, "%d", &n);
fclose (fp);
return n;
}
void ReadPloyn(Ploynomial Ployn)
{
FILE *fp;
if ((fp = fopen("PloyIn.txt", "r")) == NULL)
{
printf ("无法读入文件!");
exit (0);
}
if (Ployn)
{
fscanf (fp, "%f %d ", &Ployn -> data.coef, &Ployn -> data.expn);
}
fclose (fp);
}
void CreatePloyn(Ploynomial &head, int n) /*创造一个头结点为head,项数为m的一元多项式*/
{
int i;
Ploynomial p;
head = (Ploynomial ) malloc (sizeof (LNode)); /*创建头结点*/
head -> pNext == NULL;
for (i = 0; i < n; i++)
{
p = (Ploynomial ) malloc (sizeof (LNode)); /*创建新结点*/
ReadPloyn (head);
head -> pNext = p;
head = p;
}
}
main()
{
int i,n,m, choose;
Ploynomial PloynA, PloynA1, PloynB, PloynC;
InitList (PloynA);
InitList (PloynB);
while (1)
{
menu();
scanf ("%d", &choose);
switch (choose)
{
case 1 :
{
//PloynA = (Ploynomial)malloc(sizeof(LNode));
printf ("请读入多项式A \n");
m=ReadPloyn1 (n);
CreatePloyn (PloynA, m);
SavePloyn( PloynA, m);
printf ("a : ");
//PrintPloyn(PloynA);
printf ("\n");
//CreatePloym(PloynA, m);
break;
}
case 2 :
{
//printf ("多项式a. ");
//PrintPloyn(PloynA);
}
}
}
system ("pause");
}