您的位置:程序门 -> c/c++ -> c++ 语言



这是一段vb6的代码,谁能给翻译成c语言的


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


这是一段vb6的代码,谁能给翻译成c语言的[已结贴,结贴人:drlqyy]
发表于:2008-01-22 08:52:24 楼主
这是一段vb6的代码,谁能给翻译成c语言的  
public       tempdata()       as       long  
public       numbase(5)       as       long       '基数  
public       numunit(4)       as       long       '每单位对应的16进制数  
public       numunitprice(4)       as       long       '每单位对于的10进制数,已被从元为单位扩大1000倍  
public       type       tempfstrecord       '每一条记录的长度为26字节:  
                fsttime       as       integer  
                price       as       long  
                avgprice       as       long  
                changor       as       integer  
                unuse0       as       integer  
                unuse1       as       long  
                unuse2       as       long  
                unuse3       as       long  
end       type  
function       loadfstdata(byval       filename       as       string,       fst()       as       fstrecord)       '240个分记录,26个字节一个记录,6508字节一天  
                dim       ifile       as       integer,       i       as       integer,       j       as       integer  
                dim       tfr       as       tempfstrecord  
                dim       filep       as       long  
                dim       lendayfst       as       long:       longdayfst       =       6508  
                dim       lenminutefst       as       long:       lenminutefst       =       26  
                ifile       =       freefile  
                open       filename       for       binary       as       ifile  
                'loadfstdata       =       (lof(ifile)       -       8)       /       26       -       10  
                loadfstdata       =       lof(ifile)       /       6508  

                redim       fst(1       to       loadfstdata,       239)  
                redim       tempdata(1       to       loadfstdata)  
                redim       tempmidprice(1       to       loadfstdata)  
                redim       fstmaxprice(1       to       loadfstdata)  
                for       j       =       1       to       loadfstdata  
                                get       ifile,       1       +       (j       -       1)       *       longdayfst,       tempdata(j)  
                                get       ifile,       5       +       (j       -       1)       *       longdayfst,       tempmidprice(j)  
                                fstmaxprice(j)       =       0  
                                for       i       =       0       to       239  
                                                filep       =       (j       -       1)       *       longdayfst       +       i       *       lenminutefst       +       8       +       1  
                                                get       ifile,       filep,       tfr  
                                                fst(j,       i).fsttime       =       tfr.fsttime       +       1       'fst(i).fsttime       =       timeserial(0,       tfr.fsttime       +       1,       0)  
                                                fst(j,       i).price       =       tfr.price  
                                                fst(j,       i).avgprice       =       tfr.avgprice  
                                                fst(j,       i).changor       =       tfr.changor  
                                                if       abs(tfr.price       -       tempmidprice(j))       >       fstmaxprice(j)       then  
                                                                            fstmaxprice(j)       =       abs(tfr.price       -       tempmidprice(j))  
                                                end       if  
                                next       i  
                next       j  
                close       ifile  
end       functionfunction       getrealprice(formerprice       as       long)       as       long           '注意移植此函数是要把公共变量numbase预numunit移动移植  
    dim       i       as       integer  
                for       i       =       1       to       4                                                                                                                                       '该函数可返回32元人民币以下对于的准确价格  
                            if       formerprice       <       numbase(i)       then  
                                        getrealprice       =       (val((formerprice       -       numbase(i       -       1))       &       "000")       /       numunit(i       -       1))       +       numunitprice(i       -       1)  
                                        exit       for                                                                                                                                           '       &       000       相当于       *       1000,以‰为单位  
                            end       if  
                next       i  
end       function  
public       sub       main()  
                numbase(0)       =       1065353216:       numbase(1)       =       1082130432:       numbase(2)       =       1090519040:       numbase(3)       =       1098907648:       numbase(4)       =       1109655552       ':       numbase(5)       =       1118830592  
                numunit(0)       =       4194304:       numunit(1)       =       2097152:       numunit(2)       =       1048576:       numunit(3)       =       524288       ':       numunit(4)       =       262144  
                numunitprice(0)       =       0:       numunitprice(1)       =       4000:       numunitprice(2)       =       8000:       numunitprice(3)       =       16000       ':       numunitprice(4)       =       32000  
                readzst.show'由这个窗体去调用以上的函数,自己写  
end       sub
发表于:2008-01-22 08:54:401楼 得分:0
某很废的电脑老师唯一说过比较正确的话:有时候自己重新写一个程序,比修改他人程序要爽(仅限于小规模非结构化)
对于lz的没有格式的代码,我们又能咋样呢?
发表于:2008-01-22 08:56:482楼 得分:0
这个........
看到这个格式就晕了
发表于:2008-01-22 09:00:333楼 得分:0
vb的,有些函数不懂
发表于:2008-01-22 09:00:374楼 得分:0
这个似乎非常简单,楼主一点动手的欲望都没有?

个人建议,自己动手试试,不要这么快就否定自己
发表于:2008-01-22 09:13:245楼 得分:0
格式,注释一个都没有。郁闷至极啊!
发表于:2008-01-22 09:17:056楼 得分:0
格式的确没有,注释是有的
发表于:2008-01-22 11:23:177楼 得分:0
没有人知道?
发表于:2008-01-22 12:28:218楼 得分:0
这个程序不难啊
就是格式看着太累
发表于:2008-01-22 13:04:159楼 得分:0
c/c++ code
fst() as fstrecord 这个是什么东西
发表于:2008-01-22 13:42:5710楼 得分:0
文件中的
ifile   =   freefile

redim   fst(1   to   loadfstdata,   239)
什么意思?
发表于:2008-01-22 13:48:3011楼 得分:0
get   ifile,   1   +   (j   -   1)   *   longdayfst,   tempdata(j)
什么意思?
发表于:2008-01-22 14:05:0212楼 得分:10
fst()               as               fstrecord
这个是什么东西
===========================
fst是一个fstrecord类型的数组


ifile       =       freefile  
===========================
获取一个空闲的文件句柄


redim       fst(1       to       loadfstdata,       239)  
===========================
重新定义数组fst的大小,第一维是1   ..   loadfstdata,第二维是239


get       ifile,       1       +       (j       -       1)       *       longdayfst,       tempdata(j)  
===========================
从文件ifile中读取大小为1+(j-1)*longdayfst的数据块,存入数组tempdata(j)里面
发表于:2008-01-22 14:08:5313楼 得分:90
不知道这样对了没有,那几个redim挺迷糊的~   是全局变量重定义?

c/c++ code
#include <stdio.h> #include <math.h> typedef long long; typedef short integer; long *tempdata; long numbase[5]; /* 基数 */ long numunit[4]; /* 每单位对应的16进制数 */ long numunitprice[4]; /* 每单位对于的10进制数,已被从元为单位扩大1000倍 */ #pragma pack(push,1) typedef struct tagfstrecord{ /* 每一条记录的长度为26字节 */ integer fsttime; long price; long avgprice; integer changor; integer unuse0; long unuse1; long unuse2; long unuse3; }fstrecord; typedef fstrecord largerecord[240]; #pragma pack(pop) /* 240个分记录,26个字节一个记录,6508字节一天 */ void loadfstdata( char filename[], largerecord **retfst ) { file *ifile = null; integer i, j, loadfstdata; fstrecord tfr; long filep; long longdayfst = 6508; long lenminutefst = 26; long *tempdata, *tempmidprice, *fstmaxprice; fstrecord (*fst)[240]; ifile = fopen(filename, "rb"); fseek(ifile, 0, seek_end); loadfstdata = ftell(ifile) / 6508; fst=(largerecord *)malloc(loadfstdata*sizeof(largerecord)); tempdata = (long *)malloc(loadfstdata*sizeof(long)); tempmidprice = (long *)malloc(loadfstdata*sizeof(long)); fstmaxprice = (long *)malloc(loadfstdata*sizeof(long)); for( j = 0; j<loadfstdata; ++ j ) { fseek(ifile, j * longdayfst, seek_set); fread(&tempdata[j], sizeof(tempdata[j]), 1, ifile); fseek(ifile, 4+j * longdayfst, seek_set); fread(&tempmidprice[j], sizeof(tempmidprice[j]), 1, ifile); fstmaxprice[j] = 0; for( i = 0; i<=239; ++i ) { filep = j * longdayfst + i * lenminutefst + 8; fseek(ifile, filep, seek_set); fread( &tfr, sizeof(tfr), 1, ifile); fst[j][i].fsttime = tfr.fsttime + 1; fst[j][i].price = tfr.price; fst[j][i].avgprice= tfr.avgprice; fst[j][i].changor = tfr.changor; if( abs(tfr.price - tempmidprice[j]) > fstmaxprice[j] ) fstmaxprice[j] = abs(tfr.price - tempmidprice[j]); } } /* free(tempdata); */ free(tempmidprice); free(fstmaxprice); fclose(ifile); *retfst = fst; } /* 注意移植此函数是要把公共变量numbase预numunit移动移植 */ long getrealprice(long formerprice) { integer i; long result=0; for( i = 1; i<=4; ++ i ) /* 该函数可返回32元人民币以下对于的准确价格 */ { if( formerprice < numbase[i] ) { result = ((formerprice - numbase[i-1]) * 1000) / numunit[i-1] + numunitprice[i-1]; break; } } return result; } void main() { numbase[0] = 1065353216; numbase[1] = 1082130432; numbase[2] = 1090519040; numbase[3] = 1098907648; numbase[4] = 1109655552; /*numbase[5] = 1118830592;*/ numunit[0] = 4194304; numunit[1] = 2097152; numunit[2] = 1048576; numunit[3] = 524288; /* numunit[4] = 262144 */ numunitprice[0] = 0; numunitprice[1] = 4000; numunitprice[2] = 8000; numunitprice[3] = 16000; /* numunitprice[4] = 32000; */ readzst_show(); /* 由这个窗体去调用以上的函数,自己写 */ }


快速检索

最新资讯
热门点击