| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 837 人关注过本帖
标题:帮忙看一下为什么不行?
只看楼主 加入收藏
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:23
帖 子:1820
专家分:3681
注 册:2011-3-24
收藏
得分:0 
依据网路上教的,确实成功释放内存空间,但是另一个地方,为何第一次成功但第二次又是配不到地址?

图片附件: 游客没有浏览图片的权限,请 登录注册


程序代码:
#include <stdio.h>
#include <windows.h>

#define Max_Size 400000
#define Max_Size1 256

const char *delim1=",";
const char *delim2="|";

int My_Max_x=0;
int My_Max_y=0;
int My_Min_x=0;
int My_Min_y=0;
int ErrorCoord=0;
int parts_retested1=0;
int parts_retested2=0;

struct CoodInfo
{
    int x;
    int y;
    int sn;
    int hw;
    int sw;
    int reTest;
};

//------------------------------------------------------------------------------------------------------------------//
char * delN(char * a)
{
    int l;
    l=strlen(a);
    if(a[l-1]==10)
        a[l-1]='\0';
    return a;
}
//------------------------------------------------------------------------------------------------------------------//
int spritcount(char *strIn, const char *aaa)//計算字串中有多少分割符號
{
    int a = 0;
    unsigned int i=0;

    for(i=0; i<strlen(strIn); i++)
    {
        if (strIn[i] == aaa[0])
            a++;
    }
    return(a+1);    //符號數量+1=段落
}
//------------------------------------------------------------------------------------------------------------------//
void strSprit(char *strIn, char **strOut, const char *delim, int nSpritCount)
{
    char *temp;
    int j=0;
    temp = strtok(strIn, delim);
    while( j < nSpritCount )
    {
        strOut[j] = temp;
        j++;
        temp = strtok(NULL, delim);
    }
}
//------------------------------------------------------------------------------------------------------------------//
int CheckCood(int ICCount,CoodInfo *Cood1)
{
    int i=0,x_Max=0,y_Max=0,x_Min=0,y_Min=0;
    int New_x_Max=0,New_y_Max=0,New_x_Min=0,New_y_Min=0;
    
    for (i=0;i<ICCount;i++)
    {
        if(i==0)
        {
            x_Max=Cood1[i].x;x_Min=Cood1[i].x;
            y_Max=Cood1[i].y;y_Min=Cood1[i].y;
        }
        else
        {
            if ((Cood1[i].x>x_Max) || (Cood1[i].y>y_Max))
            {
                if (Cood1[i].x>x_Max)
                    x_Max=Cood1[i].x;
                if (Cood1[i].y>y_Max)
                    y_Max=Cood1[i].y;
            }
            else if ((Cood1[i].x<x_Min) || (Cood1[i].y<y_Min))
            {
                if (Cood1[i].x<x_Min)
                    x_Min=Cood1[i].x;
                if (Cood1[i].y<y_Min)
                    y_Min=Cood1[i].y;
            }
        }
    }
    New_x_Max=((x_Max/10)+1)*10;New_x_Min=((x_Min/10)-1)*10;
    New_y_Max=((y_Max/10)+1)*10;New_y_Min=((y_Min/10)-1)*10;
    My_Max_x=New_x_Max;My_Min_x=New_x_Min;
    My_Max_y=New_y_Max;My_Min_y=New_y_Min;

    if ((x_Min<0)||(y_Min<0)||(x_Min>1000)||(y_Min>1000))
        return -1;
    else
        return 1;
}
//------------------------------------------------------------------------------------------------------------------//
int OutBinMap(char *FileName,char *TargetFile1,char *TargetFile2,int ICCount)
{
    FILE *stream1;
    char Temp[Max_Size]={0},CodeString[Max_Size]={0};
    int i=0,j=0,k=0,ii=0,jj=0,len=0,Title=0,Paragraph=0;

    CoodInfo *Cood = (CoodInfo*)calloc(ICCount,sizeof(CoodInfo));

    if(Cood==NULL)
        return 0;
    
    //------------------------------------------------------------------------------------------收集資料

    stream1=fopen(FileName,"r");

    while(fgets(Temp, Max_Size, stream1)!=NULL)
    {
        ii++;
        if (ii==1)
        {}
        if (ii==2)
        {}
        if (ii==3)
        {
            char *temp="";
            char **part = (char**)malloc(sizeof(char*)*ICCount);

            if(part==NULL)
                return 0;

            for(i=0;i<ICCount;i++)
                part[i] = (char*)malloc(sizeof(char)*Max_Size1);

            strcpy(CodeString,delN(Temp));
            len=strlen(CodeString);

            Title = spritcount(CodeString, delim1);                    //依delim1分段落
            temp = strtok(CodeString, delim1);                        //第一次分割(part[0],part[1])
            while( j < ICCount )
            {
                sprintf(part[j] ,"%s", temp);
                j++;
                temp = strtok(NULL, delim1);
            }
            temp="";j=0;
            char *part1[5]={0};
            for (i=1;i<ICCount;i++)
            {
                Paragraph = spritcount(part[i], delim2);            //依delim2分段落
                strSprit(part[i], part1, delim2, Paragraph);        //第二次分割(part[0]....part[Paragraph])
                
                if((part1[0])&&(part1[1])&&(part1[2]))
                {
                    Cood[i-1].x = atoi(part1[0]);
                    Cood[i-1].y = atoi(part1[1]);
                    Cood[i-1].sn = atoi(part1[2]);
                }
            }
            for(i=0;i<Max_Size1;i++)
                free(part[i]);
            free(part);
            part=NULL;
        }
        else if (ii==4)
        {
            char *temp="";
            char **part = (char**)malloc(sizeof(char*)*ICCount);

            if(part==NULL)
                return 0;

            for(i=0;i<ICCount;i++)
                part[i] = (char*)malloc(sizeof(char)*Max_Size1);

            strcpy(CodeString,delN(Temp));
            len=strlen(CodeString);

            Title = spritcount(CodeString, delim1);                    //依delim1分段落
            temp = strtok(CodeString, delim1);                        //第一次分割(part[0],part[1])
            while( j < ICCount )
            {
                sprintf(part[j] ,"%s", temp);
                j++;
                temp = strtok(NULL, delim1);
            }
            temp="";j=0;
            char *part1[5]={0};
            for (i=1;i<ICCount;i++)
            {
                Paragraph = spritcount(part[1], delim2);            //依delim2分段落
                strSprit(part[i], part1, delim2, Paragraph);        //第二次分割(part[0]....part[Paragraph])
                
                if((part1[0])&&(part1[1]))
                {
                    Cood[i-1].hw = atoi(part1[0]);
                    Cood[i-1].sn = atoi(part1[1]);
                }
            }
            for(i=0;i<Max_Size1;i++)
                free(part[i]);
            free(part);
            part=NULL;
        }
        else if (ii>4)
            break;

        memset(CodeString,0,sizeof(CodeString));
        memset(Temp,0,sizeof(Temp));
    }
    fclose(stream1);
    //------------------------------------------------------------------------------------------
    if(CheckCood(ICCount,Cood)==1)
    {
        char ***NewCood = NULL;
        NewCood = (char***)malloc(sizeof(*NewCood)*My_Max_x);
        
        if(NewCood==NULL)
            return 0;

        for(i=(My_Max_x-1);i>=0;--i)
        {
            NewCood[i] = (char**)malloc(sizeof(*NewCood[i])*My_Max_y);
            for(j=(My_Max_y-1);j>=0;--j)
                NewCood[i][j] = (char*)malloc(sizeof(*NewCood[i][j])*3);
        }

        for(i=(My_Max_x-1);i>=0;--i)
            for(j=(My_Max_y-1);j>=0;--j)
                for(k=(3-1);k>=0;--k)
                    NewCood[i][j][k]='\0';

        for(i=0;i<ICCount;i++)
        {
            char tmp1[2]={0};
            itoa(Cood[i].hw,tmp1,10);
            if (strlen(NewCood[Cood[i].x][Cood[i].y])==0)
                Cood[i].reTest = 0;
            else
            {
                Cood[i].reTest = 1;
                parts_retested1++;
            }
            strcpy(NewCood[Cood[i].x][Cood[i].y],tmp1) ;
        }
        stream1 = fopen(TargetFile1, "a+" );//HW
        for(int num0=0;num0<3;num0++)
        {
            fprintf(stream1,",");
            for(int num1=0;num1<My_Max_x;num1++)
            {
                if (num0==0)
                    fprintf(stream1,"0,");
                else if (num0==1)
                {
                    int a=num1/10;
                    fprintf(stream1,"%d,",a);
                }
                else if (num0==2)
                {
                    int a=num1%10;
                    fprintf(stream1,"%d,",a);
                }
            }
            fprintf(stream1,"\n");
        }
        
        char *MyString1=NULL;
        MyString1 = (char*)malloc(sizeof(*MyString1)*(My_Max_x+5));

        if(MyString1==NULL)
            return 0;

        for(i=0;i<My_Max_y;i++)
        {
            jj=0;
            memset(MyString1,0,sizeof(MyString1));
            for(int ii=0;ii<My_Max_x;ii++)
            {
                if(strcmp(NewCood[ii][i],"000")>0)
                    jj+=sprintf(MyString1+jj,"%s,",NewCood[ii][i]);
                else
                    jj+=sprintf(MyString1+jj,",");
            }
            fprintf(stream1,"%d,%s\n",i,MyString1);
        }
        fprintf(stream1,",\n,\n,\n");
        MyString1=NULL;

        //ReTest IC
        for(i=0;i<ICCount;i++)
        {
            if (i==0)
                fprintf(stream1,"%s,%s,%s,%s\n","X","Y","Site","HW");
            if (Cood[i].reTest ==1)
                fprintf(stream1,"%d,%d,%d,%d\n",Cood[i].x,Cood[i].y,Cood[i].sn,Cood[i].hw);
        }
        fclose(stream1);

        for(i=0;My_Max_x>i;++i)
        {
            for(j=0;My_Max_y>j;++j)
            {
                free(NewCood[i][j]);
                NewCood[i][j]=NULL;
            }
            free(NewCood[i]);
            NewCood[i]=NULL;
        }
        free(NewCood);
        NewCood = NULL;
    }
    else
        return 0;
    //------------------------------------------------------------------------------------------
    if(CheckCood(ICCount,Cood)==1)
    {
        char ***NewCood = NULL;
        NewCood = (char***)malloc(sizeof(*NewCood)*My_Max_x);

        if(NewCood==NULL)
            return 0;

        for(i=(My_Max_x-1);i>=0;--i)
        {
            NewCood[i] = (char**)malloc(sizeof(*NewCood[i])*My_Max_y);
            for(j=(My_Max_y-1);j>=0;--j)
                NewCood[i][j] = (char*)malloc(sizeof(*NewCood[i][j])*3);
        }
        for(i=(My_Max_x-1);i>=0;--i)
            for(j=(My_Max_y-1);j>=0;--j)
                for(k=(3-1);k>=0;--k)
                    NewCood[i][j][k]='\0';

        for(i=0;i<ICCount;i++)
        {
            char tmp1[2]={0};
            itoa(Cood[i].sw,tmp1,10);
            if (strlen(NewCood[Cood[i].x][Cood[i].y])==0)
                Cood[i].reTest = 0;
            else
            {
                Cood[i].reTest = 1;
                parts_retested2++;
            }
            strcpy(NewCood[Cood[i].x][Cood[i].y],tmp1) ;
        }
        stream1 = fopen(TargetFile2, "a+" );//SW
        for(int num0=0;num0<3;num0++)
        {
            fprintf(stream1,",");
            for(int num1=0;num1<My_Max_x;num1++)
            {
                if (num0==0)
                    fprintf(stream1,"0,");
                else if (num0==1)
                {
                    int a=num1/10;
                    fprintf(stream1,"%d,",a);
                }
                else if (num0==2)
                {
                    int a=num1%10;
                    fprintf(stream1,"%d,",a);
                }
            }
            fprintf(stream1,"\n");
        }

        char *MyString1=NULL;jj=0;
        MyString1 = (char*)malloc(sizeof(*MyString1)*(My_Max_x+5));

        if(MyString1==NULL)
                return 0;

        for(i=0;i<My_Max_y;i++)
        {
            jj=0;
            memset(MyString1,0,sizeof(MyString1));
            for(int ii=0;ii<My_Max_x;ii++)
            {
                if(strcmp(NewCood[ii][i],"000")>0)
                    jj+=sprintf(MyString1+jj,"%s,",NewCood[ii][i]);
                else
                    jj+=sprintf(MyString1+jj,",");
            }
            fprintf(stream1,"%d,%s\n",i,MyString1);
        }
        fprintf(stream1,",\n,\n,\n");
        MyString1=NULL;

        //ReTest IC
        for(i=0;i<ICCount;i++)
        {
            if (i==0)
                fprintf(stream1,"%s,%s,%s,%s\n","X","Y","Site","SW");
            if (Cood[i].reTest ==1)
                fprintf(stream1,"%d,%d,%d,%d\n",Cood[i].x,Cood[i].y,Cood[i].sn,Cood[i].sw);
        }
        fclose(stream1);

        for(i=0;My_Max_x>i;++i)
        {
            for(j=0;My_Max_y>j;++j)
            {
                free(NewCood[i][j]);
                NewCood[i][j]=NULL;
            }
            free(NewCood[i]);
            NewCood[i]=NULL;
        }
        free(NewCood);
        NewCood = NULL;
    }
    else
        return 0;

    free(Cood);
    Cood=NULL;

    return 1;
}

void main(int argc, char* argv[])
{
    int A=OutBinMap("C:\\TMB\\Transform\\AAAA.csv","C:\\TMB\\Transform\\HW.csv","C:\\TMB\\Transform\\SW.csv",12355);
    char B[1]={0};
    itoa(A,B,10);
    MessageBox(NULL,B,"Test Result",MB_OK);
}

不要選我當版主
2015-03-17 15:27
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:0 
3個*號,我已經徹底暈掉了,不知道。

授人以渔,不授人以鱼。
2015-03-17 16:04
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:23
帖 子:1820
专家分:3681
注 册:2011-3-24
收藏
得分:0 

真的很灵异,我改短一点好了。

不要選我當版主
2015-03-17 16:09
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:0 
3個*號,虧你弄得出來,我2個都要死。

授人以渔,不授人以鱼。
2015-03-17 16:52
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:0 
其實,你非要用C做不可麽?用C++的智能指針,可以免去很多麻煩的啦。

授人以渔,不授人以鱼。
2015-03-17 17:40
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:23
帖 子:1820
专家分:3681
注 册:2011-3-24
收藏
得分:0 
不是我爱用,因为我只会C,学校只教过C.

不要選我當版主
2015-03-17 18:14
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:0 
拿C++的現成庫寫C程序,又不是要用面向對象思想,當多點功能罷了。

授人以渔,不授人以鱼。
2015-03-17 18:20
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:23
帖 子:1820
专家分:3681
注 册:2011-3-24
收藏
得分:0 
单独只选择跑一项都OK,但是跑第一个后再跑第二个,第二个就一定配不到地址,真是很灵异,甚至连变量名称都设成不一样,状况还是一样....

.h
程序代码:
#ifdef __cpluscplus
#define EXPORT extern "C" __declspec(dllexport)
#else
#define EXPORT __declspec(dllexport)
#endif

EXPORT int OutBinMap(int,char*,char*,int);


.cpp
程序代码:
#include "OutBinMap.h"
#include <stdio.h>
#include <windows.h>

#define Max_Size 400000
#define Max_Size1 256

const char *delim1=",";
const char *delim2="|";

int My_Max_x=0;
int My_Max_y=0;
int My_Min_x=0;
int My_Min_y=0;
int ErrorCoord=0;
int parts_retested1=0;
int parts_retested2=0;
int ICCount=0;

struct CoodInfo
{
    int x;
    int y;
    int sn;
    int hw;
    int sw;
    int reTest;
};

int __stdcall DllMain(HINSTANCE hInstance, DWORD dwReason, PVOID pvReserved)
{
    return TRUE;
}
//------------------------------------------------------------------------------------------------------------------//
char * delN(char * a)
{
    int l;
    l=strlen(a);
    if(a[l-1]==10)
        a[l-1]='\0';
    return a;
}
//------------------------------------------------------------------------------------------------------------------//
int spritcount(char *strIn, const char *aaa)//計算字串中有多少分割符號
{
    int a = 0;
    unsigned int i=0;

    for(i=0; i<strlen(strIn); i++)
    {
        if (strIn[i] == aaa[0])
            a++;
    }
    return(a+1);    //符號數量+1=段落
}
//------------------------------------------------------------------------------------------------------------------//
void strSprit(char *strIn, char **strOut, const char *delim, int nSpritCount)
{
    char *temp;
    int j=0;
    temp = strtok(strIn, delim);
    while( j < nSpritCount )
    {
        strOut[j] = temp;
        j++;
        temp = strtok(NULL, delim);
    }
}
//------------------------------------------------------------------------------------------------------------------//
int CheckCood(int ICCount,CoodInfo *Cood1)
{
    int i=0,x_Max=0,y_Max=0,x_Min=0,y_Min=0;
    int New_x_Max=0,New_y_Max=0,New_x_Min=0,New_y_Min=0;
    
    for (i=0;i<ICCount;i++)
    {
        if(i==0)
        {
            x_Max=Cood1[i].x;x_Min=Cood1[i].x;
            y_Max=Cood1[i].y;y_Min=Cood1[i].y;
        }
        else
        {
            if ((Cood1[i].x>x_Max) || (Cood1[i].y>y_Max))
            {
                if (Cood1[i].x>x_Max)
                    x_Max=Cood1[i].x;
                if (Cood1[i].y>y_Max)
                    y_Max=Cood1[i].y;
            }
            else if ((Cood1[i].x<x_Min) || (Cood1[i].y<y_Min))
            {
                if (Cood1[i].x<x_Min)
                    x_Min=Cood1[i].x;
                if (Cood1[i].y<y_Min)
                    y_Min=Cood1[i].y;
            }
        }
    }
    New_x_Max=((x_Max/10)+1)*10;New_x_Min=((x_Min/10)-1)*10;
    New_y_Max=((y_Max/10)+1)*10;New_y_Min=((y_Min/10)-1)*10;
    My_Max_x=New_x_Max;My_Min_x=New_x_Min;
    My_Max_y=New_y_Max;My_Min_y=New_y_Min;

    if ((x_Min<0)||(y_Min<0)||(x_Min>1000)||(y_Min>1000))
        return 0;
    else
        return 1;
}
//------------------------------------------------------------------------------------------------------------------//
int GenerateHWBinMap(char *TargetFile,CoodInfo *Cood1)
{
    FILE *stream1;
    int i=0,j=0,k=0,jj=0;

    char ***HWCood1 = NULL;
    HWCood1 = (char***)malloc(sizeof(*HWCood1)*My_Max_x);
    
    if(HWCood1==NULL)
        return 0;

    for(i=(My_Max_x-1);i>=0;--i)
    {
        HWCood1[i] = (char**)malloc(sizeof(*HWCood1[i])*My_Max_y);
        for(j=(My_Max_y-1);j>=0;--j)
            HWCood1[i][j] = (char*)malloc(sizeof(*HWCood1[i][j])*3);
    }

    for(i=(My_Max_x-1);i>=0;--i)
        for(j=(My_Max_y-1);j>=0;--j)
            for(k=(3-1);k>=0;--k)
                HWCood1[i][j][k]='\0';

    for(i=0;i<ICCount;i++)
    {
        char tmp1[2]={0};
        itoa(Cood1[i].hw,tmp1,10);
        if (strlen(HWCood1[Cood1[i].x][Cood1[i].y])==0)
            Cood1[i].reTest = 0;
        else
        {
            Cood1[i].reTest = 1;
            parts_retested1++;
        }
        strcpy(HWCood1[Cood1[i].x][Cood1[i].y],tmp1) ;
    }
    stream1 = fopen(TargetFile, "a+" );//HW

    printf("\n %s 處理中 ...\n",TargetFile);

    for(int num0=0;num0<3;num0++)
    {
        fprintf(stream1,",");
        for(int num1=0;num1<My_Max_x;num1++)
        {
            if (num0==0)
                fprintf(stream1,"0,");
            else if (num0==1)
            {
                int a=num1/10;
                fprintf(stream1,"%d,",a);
            }
            else if (num0==2)
            {
                int a=num1%10;
                fprintf(stream1,"%d,",a);
            }
        }
        fprintf(stream1,"\n");
    }
    
    char *MyString1=NULL;
    MyString1 = (char*)malloc(sizeof(*MyString1)*(My_Max_x+5));

    if(MyString1==NULL)
        return 0;

    for(i=0;i<My_Max_y;i++)
    {
        jj=0;
        memset(MyString1,0,sizeof(MyString1));
        for(int ii=0;ii<My_Max_x;ii++)
        {
            if(strcmp(HWCood1[ii][i],"000")>0)
                jj+=sprintf(MyString1+jj,"%s,",HWCood1[ii][i]);
            else
                jj+=sprintf(MyString1+jj,",");
        }
        fprintf(stream1,"%d,%s\n",i,MyString1);
    }
    fprintf(stream1,",\n,\n,\n");
    //free(MyString1);
    MyString1=NULL;

    //ReTest IC
    for(i=0;i<ICCount;i++)
    {
        if (i==0)
            fprintf(stream1,"%s,%s,%s,%s\n","X","Y","Site","HW");
        if (Cood1[i].reTest ==1)
            fprintf(stream1,"%d,%d,%d,%d\n",Cood1[i].x,Cood1[i].y,Cood1[i].sn,Cood1[i].hw);
    }
    fclose(stream1);

    for(i=0;My_Max_x>i;++i)
    {
        for(j=0;My_Max_y>j;++j)
        {
            free(HWCood1[i][j]);
            HWCood1[i][j]=NULL;
        }
        free(HWCood1[i]);
        HWCood1[i]=NULL;
    }
    free(HWCood1);
    HWCood1 = NULL;

    return 1;
}
//------------------------------------------------------------------------------------------------------------------//
int GenerateSWBinMap(char *TargetFile,CoodInfo *Cood1)
{
    FILE *stream1;
    int i=0,j=0,k=0,jj=0;

    char ***SWCood1 = NULL;
    SWCood1 = (char***)malloc(sizeof(*SWCood1)*My_Max_x);

    if(SWCood1==NULL)
        return 0;

    for(i=(My_Max_x-1);i>=0;--i)
    {
        SWCood1[i] = (char**)malloc(sizeof(*SWCood1[i])*My_Max_y);
        for(j=(My_Max_y-1);j>=0;--j)
            SWCood1[i][j] = (char*)malloc(sizeof(*SWCood1[i][j])*3);
    }
    for(i=(My_Max_x-1);i>=0;--i)
        for(j=(My_Max_y-1);j>=0;--j)
            for(k=(3-1);k>=0;--k)
                SWCood1[i][j][k]='\0';

    for(i=0;i<ICCount;i++)
    {
        char tmp1[2]={0};
        itoa(Cood1[i].sw,tmp1,10);
        if (strlen(SWCood1[Cood1[i].x][Cood1[i].y])==0)
            Cood1[i].reTest = 0;
        else
        {
            Cood1[i].reTest = 1;
            parts_retested2++;
        }
        strcpy(SWCood1[Cood1[i].x][Cood1[i].y],tmp1) ;
    }
    stream1 = fopen(TargetFile, "a+" );//SW

    printf("\n %s 處理中 ...\n",TargetFile);

    for(int num0=0;num0<3;num0++)
    {
        fprintf(stream1,",");
        for(int num1=0;num1<My_Max_x;num1++)
        {
            if (num0==0)
                fprintf(stream1,"0,");
            else if (num0==1)
            {
                int a=num1/10;
                fprintf(stream1,"%d,",a);
            }
            else if (num0==2)
            {
                int a=num1%10;
                fprintf(stream1,"%d,",a);
            }
        }
        fprintf(stream1,"\n");
    }

    char *MyString1=NULL;
    MyString1 = (char*)malloc(sizeof(*MyString1)*(My_Max_x+5));

    if(MyString1==NULL)
            return 0;

    for(i=0;i<My_Max_y;i++)
    {
        jj=0;
        memset(MyString1,0,sizeof(MyString1));
        for(int ii=0;ii<My_Max_x;ii++)
        {
            if(strcmp(SWCood1[ii][i],"000")>0)
                jj+=sprintf(MyString1+jj,"%s,",SWCood1[ii][i]);
            else
                jj+=sprintf(MyString1+jj,",");
        }
        fprintf(stream1,"%d,%s\n",i,MyString1);
    }
    fprintf(stream1,",\n,\n,\n");
    //free(MyString1);
    MyString1=NULL;

    //ReTest IC
    for(i=0;i<ICCount;i++)
    {
        if (i==0)
            fprintf(stream1,"%s,%s,%s,%s\n","X","Y","Site","SW");
        if (Cood1[i].reTest ==1)
            fprintf(stream1,"%d,%d,%d,%d\n",Cood1[i].x,Cood1[i].y,Cood1[i].sn,Cood1[i].sw);
    }
    fclose(stream1);

    for(i=0;My_Max_x>i;++i)
    {
        for(j=0;My_Max_y>j;++j)
        {
            free(SWCood1[i][j]);
            SWCood1[i][j]=NULL;
        }
        free(SWCood1[i]);
        SWCood1[i]=NULL;
    }
    free(SWCood1);
    SWCood1 = NULL;

    return 1;
}
//------------------------------------------------------------------------------------------------------------------//
EXPORT int OutBinMap(int Mode,char *FileName,char *TargetFile1,int ICCount1)
{
    FILE *stream1;
    char Temp[Max_Size]={0},CodeString[Max_Size]={0};
    int i=0,j=0,k=0,ii=0,jj=0,len=0,Title=0,Paragraph=0;
    
    ICCount=ICCount1;
    CoodInfo *Cood = (CoodInfo*)calloc(ICCount,sizeof(CoodInfo));

    if(Cood==NULL)
        return 0;

    //------------------------------------------------------------------------------------------收集資料
    stream1=fopen(FileName,"r");
    while(fgets(Temp, Max_Size, stream1)!=NULL)
    {
        ii++;
        if (ii==1)
        {}
        if (ii==2)
        {}
        if (ii==3)
        {
            char *temp="";
            char **part = (char**)malloc(sizeof(char*)*ICCount);

            if(part==NULL)
                return 0;

            for(i=0;i<ICCount;i++)
                part[i] = (char*)malloc(sizeof(char)*Max_Size1);

            strcpy(CodeString,delN(Temp));
            len=strlen(CodeString);

            Title = spritcount(CodeString, delim1);                    //依delim1分段落
            temp = strtok(CodeString, delim1);                        //第一次分割(part[0],part[1])
            while( j < ICCount )
            {
                sprintf(part[j] ,"%s", temp);
                j++;
                temp = strtok(NULL, delim1);
            }
            temp="";j=0;
            char *part1[5]={0};
            for (i=1;i<ICCount;i++)
            {
                Paragraph = spritcount(part[i], delim2);            //依delim2分段落
                strSprit(part[i], part1, delim2, Paragraph);        //第二次分割(part[0]....part[Paragraph])
                
                if((part1[0])&&(part1[1])&&(part1[2]))
                {
                    Cood[i-1].x = atoi(part1[0]);
                    Cood[i-1].y = atoi(part1[1]);
                    Cood[i-1].sn = atoi(part1[2]);
                }
            }
            for(i=0;i<Max_Size1;i++)
                free(part[i]);
            free(part);
            part=NULL;
        }
        else if (ii==4)
        {
            char *temp="";
            char **part = (char**)malloc(sizeof(char*)*ICCount);

            if(part==NULL)
                return 0;

            for(i=0;i<ICCount;i++)
                part[i] = (char*)malloc(sizeof(char)*Max_Size1);

            strcpy(CodeString,delN(Temp));
            len=strlen(CodeString);

            Title = spritcount(CodeString, delim1);                    //依delim1分段落
            temp = strtok(CodeString, delim1);                        //第一次分割(part[0],part[1])
            while( j < ICCount )
            {
                sprintf(part[j] ,"%s", temp);
                j++;
                temp = strtok(NULL, delim1);
            }
            temp="";j=0;
            char *part1[5]={0};
            for (i=1;i<ICCount;i++)
            {
                Paragraph = spritcount(part[1], delim2);            //依delim2分段落
                strSprit(part[i], part1, delim2, Paragraph);        //第二次分割(part[0]....part[Paragraph])
                
                if((part1[0])&&(part1[1]))
                {
                    Cood[i-1].hw = atoi(part1[0]);
                    Cood[i-1].sw = atoi(part1[1]);
                }
            }
            for(i=0;i<Max_Size1;i++)
                free(part[i]);
            free(part);
            part=NULL;
        }
        else if (ii>4)
            break;

        memset(CodeString,0,sizeof(CodeString));
        memset(Temp,0,sizeof(Temp));
    }
    fclose(stream1);
    
    if(CheckCood(ICCount,Cood)==1)
    {
        if (Mode==0)
            if (GenerateHWBinMap(TargetFile1,Cood)!=1)
                return 0;
        if (Mode==1)
            if (GenerateSWBinMap(TargetFile1,Cood)!=1)
                return 0;
    }
    else
        return 0;

    free(Cood);
    Cood=NULL;

    return 1;
}
//------------------------------------------------------------------------------------------------------------------//
/*
void main(int argc, char* argv[])
{
    if (OutBinMap(0,"C:\\TMB\\Transform\\AAAA.csv","C:\\TMB\\Transform\\HW.csv",12355)==1)
        MessageBox(NULL,"OK !","Test Result",MB_OK);
    else
        MessageBox(NULL,"Error !","Test Result",MB_OK);

    if (OutBinMap(1,"C:\\TMB\\Transform\\AAAA.csv","C:\\TMB\\Transform\\SW.csv",12355)==1)
        MessageBox(NULL,"OK !","Test Result",MB_OK);
    else
        MessageBox(NULL,"Error !","Test Result",MB_OK);
}
*/
//------------------------------------------------------------------------------------------------------------------//


摆明是逼我分开写成两个DLL来做

[ 本帖最后由 wube 于 2015-3-17 18:24 编辑 ]

不要選我當版主
2015-03-17 18:22
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:23
帖 子:1820
专家分:3681
注 册:2011-3-24
收藏
得分:0 
睡夢中,突然周公突然有指示,我明天再改個寫法,說不到問題就在那。

不要選我當版主
2015-03-18 05:35
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:23
帖 子:1820
专家分:3681
注 册:2011-3-24
收藏
得分:0 
問題的根源也許是在這,看來陣列傳遞的弱點,不克服不行,今天上班再試試看。

图片附件: 游客没有浏览图片的权限,请 登录注册


話說今年主要的工作要改變了,先預告一下,以前VB和C的開發都已經交接給公司的新人了,
下個月開始應該會轉到MYSQL和ASP.NET區去了。

不要選我當版主
2015-03-18 06:01
快速回复:帮忙看一下为什么不行?
数据加载中...
 
   



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

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