| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 260 人关注过本帖
标题:关于文件操作。。
只看楼主 加入收藏
laoA
Rank: 2
等 级:论坛游民
帖 子:24
专家分:59
注 册:2012-11-18
结帖率:66.67%
收藏
已结贴  问题点数:20 回复次数:2 
关于文件操作。。
#include<stdio.h>

#include<stdlib.h>
#include<string.h>
#define LEN 40

int main(int argc,char *argv[])
{
    FILE *in,*out;
    int ch;
    char name[LEN];
    int count=0;

    if(argc<2)
    {   
        fprintf(stderr,"Usage: %s filename\n",argv[0]);
        exit(1);
    }

    if((in=fopen(argv[1],"r"))==NULL)
    {
        fprintf(stderr,"I couldn't open the file \"%s\"\n",
            argv[1]);
        exit(2);


    }
    strcpy(name,argv[1]);
    strcat(name,".red");
    if((out=fopen(name,"w"))==NULL)
    {
        fprintf(stderr,"Can't creat puput file.\n");
        exit(3);

    }

    while((ch=getc(in))!=EOF)
        if(count++%3==0)
            putc(ch,out);

    if(fclose(in)!=0||fclose(out)!=0)
        fprintf(stderr,"Error in closing files.\n");

    return 0;


}

代码如上,生成.exe为peoject8.exe  用命令行操作时,我把peoject8.exe复制到了lenovo文件夹下,并创建了tet.txt文件,
运行后提示I couldn't open the file "tet"

因为是刚接触文件操作,所以不知道哪里错了,希望大家可以指导下
搜索更多相关主题的帖子: include count file 
2012-11-26 19:43
pauljames
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:千里冰封
威 望:9
帖 子:1555
专家分:10000
注 册:2011-5-8
收藏
得分:20 
运行的时候要带参数,比如peoject8 tet.txt

经常不在线不能及时回复短消息,如有c/单片机/运动控制/数据采集等方面的项目难题可加qq1921826084。
2012-11-26 19:52
laoA
Rank: 2
等 级:论坛游民
帖 子:24
专家分:59
注 册:2012-11-18
收藏
得分:0 
回复 2楼 pauljames
额,谢谢
2012-11-26 20:23
快速回复:关于文件操作。。
数据加载中...
 
   



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

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