| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1555 人关注过本帖
标题:C语言问题,求助高手,希望大家多多帮助,谢谢
只看楼主 加入收藏
liyanhong
Rank: 3Rank: 3
来 自:水星
等 级:禁止访问
威 望:8
帖 子:1867
专家分:0
注 册:2008-5-3
收藏
得分:0 
学到了不少

爱上你 是 我的错  可是离 开  又舍不得  听着你为我写的歌     好难过
如果说 我说如果  我们还 能  重新来过   不去计 较 谁对谁错  会怎么做
2008-10-11 17:33
flydream0
Rank: 1
等 级:新手上路
帖 子:20
专家分:7
注 册:2008-10-10
收藏
得分:0 
试下这个:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define Dmalloc    malloc
#define Drealloc realloc
#define Dfree free
#define FS_Open(name, oflag)             fopen(name, oflag)
#define FS_Close(fp)                     fclose(fp)
#define FS_Seek(fp, offset, whence)     fseek(fp, offset, whence)
#define FS_Tell(fp)                     ftell(fp)
#define FS_Read(ptr, size, nitem, fp)     fread(ptr, size, nitem, fp)
#define FS_Write(ptr, size, nitem, fp)     fwrite(ptr, size, nitem, fp)


void main(void)
{
    FILE *stream,*stream2;
    char *sfilepath="d:\\mcutest\\tc\\fu\\file3.txt";
    char *dfilepath="d:\\mcutest\\tc\\fu\\file4.txt";
    char *chrTarget,*chrSource;
    char *chrbegin;
    int inifilesize,intnumread,intpos,intsum,intTemp1,intTemp2;

   
    if( (stream = FS_Open( sfilepath, "r+b" )) == NULL )
    {
      printf( "The file 'test.txt' was not opened or not exist!\n" );
    }
   else
   {
       if (FS_Seek(stream, 0, SEEK_END)!= 0) //move the file point the end of file
        {
            printf( "move the file point to the end of file failed!\n" );
        }
        inifilesize=FS_Tell(stream);//get current file size
        if (FS_Seek(stream, 0, SEEK_SET)!= 0) //move the file point to the begin of file again
        {
            printf( "move the file point to the begin of file failed!\n" );
        }
        chrSource=(char*)Dmalloc(inifilesize);
        if( NULL==chrSource )
        {
            printf( "Insufficient memory available\n" );
        }
        intnumread = FS_Read( chrSource, sizeof( char ), inifilesize, stream );//get file stream
        chrbegin=chrSource;
        
        chrTarget=(char*)Dmalloc(inifilesize);
        if( NULL==chrTarget )
        {
            printf( "Insufficient memory available\n" );
        }
        printf("******************************************************************************\n");
        printf("The contents of test.txt is showed as below:\n%s\n", chrSource );

        intsum=0;
        for (intTemp1=0;intTemp1<inifilesize;intTemp1++)
        {
            intpos=strcspn(chrbegin,"mA");
            for (intTemp2=0;intTemp2<intpos;intTemp2++)
            {
                if (chrbegin-chrSource>=inifilesize)
                    break;
                *(chrTarget+intsum)=*chrbegin;
                chrbegin++;
               
                intsum++;
            }
            if (chrbegin-chrSource>=inifilesize)
                break;
            else
                chrbegin+=strlen("mA");
        }
        *(chrTarget+intsum)=0;
        printf("%s ",chrTarget);

        if( (stream2 = FS_Open( dfilepath, "a" )) == NULL )
        {
            printf( "The file 'test.txt' was not opened or not exist!\n" );
        }
        intnumread = FS_Write( chrTarget, sizeof( char ), strlen(chrTarget), stream2 );
        printf("the number of characters had been writeen is:%d",intnumread);
   }
   Dfree(chrSource);
   Dfree(chrTarget);
   FS_Close(stream);
   FS_Close(stream2);
}
2008-10-11 18:24
StarWing83
Rank: 8Rank: 8
来 自:仙女座大星云
等 级:贵宾
威 望:19
帖 子:3951
专家分:748
注 册:2007-11-16
收藏
得分:0 
LS的代码可谓之Vx的“百花齐放”了~~不过,给库函数做宏的确不是个好主意,要么你就写shell-function用来调试,要么你根本就直接使用库函数,这么做不是很浪费么??

专心编程………
飞燕算法初级群:3996098
我的Blog
2008-10-12 05:16
快速回复:C语言问题,求助高手,希望大家多多帮助,谢谢
数据加载中...
 
   



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

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