| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 559 人关注过本帖
标题:为什么从文件中读取的数据保存到另一个文件中就成乱码了 ?
只看楼主 加入收藏
zc1992312
Rank: 2
等 级:论坛游民
帖 子:43
专家分:12
注 册:2013-3-20
结帖率:57.14%
收藏
已结贴  问题点数:20 回复次数:3 
为什么从文件中读取的数据保存到另一个文件中就成乱码了 ?
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");      
}
搜索更多相关主题的帖子: include 
2013-10-26 13:57
yuccn
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:何方
等 级:版主
威 望:167
帖 子:6815
专家分:42393
注 册:2010-12-16
收藏
得分:10 
估计是读写格式不一致咯

我行我乐
公众号:逻辑客栈
我的博客:
https://blog.yuccn. net
2013-10-28 12:14
zc1992312
Rank: 2
等 级:论坛游民
帖 子:43
专家分:12
注 册:2013-3-20
收藏
得分:0 
回复 2楼 yuccn
什么意思啊 ?  能具体点嘛?
 谢谢
2013-10-28 18:18
MissingLCY
Rank: 2
等 级:论坛游民
帖 子:5
专家分:42
注 册:2013-9-24
收藏
得分:10 
ployout.txt是什么,全部程序没搬上来吧
2013-10-29 13:00
快速回复:为什么从文件中读取的数据保存到另一个文件中就成乱码了 ?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.041979 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved