| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 228 人关注过本帖
标题:求教关于文件的写入
取消只看楼主 加入收藏
qijinnian
Rank: 1
等 级:新手上路
帖 子:14
专家分:8
注 册:2012-8-29
结帖率:50%
收藏
已结贴  问题点数:10 回复次数:0 
求教关于文件的写入
为什么我写的代码无法把输出写进文件out.txt里面;
下面是我的代码:
#include <stdio.h>
#include <stdlib.h>

int main()
{
    FILE *out;
    int flag=0;
    int N_;
    int i,j;
      scanf("%d",&N_);

      if((out=fopen("out.txt","w"))==NULL)
      {
          printf("Wrong!");
          return (-1);
      }
    while(N_!=0)
    {
        if(N_%2==0)
        {
            for(i=1; i<=N_; i++)
            {
                if(flag==1&&N_!=0)
                 {fputc('\n',out); printf("\n");}
                int k=1;
                for (j=0; j<2*N_-1&&k<=2*N_-1; j++)
                {
                    if (k<=N_-i)
                    {
                       fputc('\0',out); printf(" ");
                        k++;
                    }
                    else if (k>(N_-i)&&k<=(2*N_-1)-(N_-i))
                    {
                       fputc('+',out);printf("+");
                        k++;
                    }
                    else if(k>(2*N_-1)-(N_-i)&&k<=2*N_-1)
                        {
                            fputc(' ',out);printf(" ");
                        k++;}
                   flag=1;
                }
            }
        }
        else if(N_%2!=0)
        {
           for (i=N_;i>=1;i--)
            {
                if (flag==1&&N_!=0)
                {fputc('\n',out);printf("\n");}
                int k=1;
                for(j=0;j<2*N_-1&&k<=2*N_-1;j++)
                {
                    if(k<=N_-i)
                    {fputc(' ',out);printf(" ");
                    k++;}
                    else if(k>(N_-i)&&k<=(2*N_-1)-(N_-i))
                    {fputc('+',out);printf("+");
                    k++;}
                    else if(k>(2*N_-1)-(N_-i)&&k<=2*N_-1)
                    {fputc(' ',out);printf(" ");
                    k++;}
                    flag=1;
                }
            }
        }
         fputc('\n',out);printf("\n");
        scanf("%d",&N_);
    }
    fclose(out);
    return 0;
}
搜索更多相关主题的帖子: include return 
2012-12-08 11:25
快速回复:求教关于文件的写入
数据加载中...
 
   



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

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