请问如何把下列的 C 语言代码转化为 C# 代码, 谢谢了,

mycolin 2008-02-16 02:25:03
#include <stdio.h>
   #include <conio.h>
   #include <stdlib.h>
  
   typedef struct {
   unsigned long date;
   unsigned long open;
   unsigned long high;
   unsigned long low;
   unsigned long close;
   unsigned long travl;
   unsigned long traca;
   char unuse[12];
   } RECORD;
  
RECORD reco;
int readrec(FILE *);
  
void main()
{
FILE *fp;
if((fp = fopen("000001.day","rb")) == NULL) // 打开深发展日线
{
printf("Error: Can^t open 000001.DAY !\n");
exit(0);
}

readrec(fp);
fclose(fp);
if(getch()==0)
getch();
exit(0);
}
  
int readrec(FILE *fp)
{
float fn;
while (! feof(fp))
{
fread(&reco,sizeof(RECORD),1,fp);
printf("%10lu ",reco.date);
fn=float(reco.open)/1000;
printf("%8.2f ",fn);
fn=float(reco.high)/1000;
printf("%8.2f ",fn);
fn=float(reco.low)/1000;
printf("%8.2f ",fn);
fn=float(reco.close)/1000;
printf("%8.2f ",fn);
printf("%8lu ",reco.travl);
printf("%8lu\n",reco.traca);
}

printf("\n");
return 0;
}
...全文
163 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
chengqscjh 2008-02-17
  • 打赏
  • 举报
回复
mark,up
真相重于对错 2008-02-17
  • 打赏
  • 举报
回复
c++ long --->c# int
genlinux 2008-02-16
  • 打赏
  • 举报
回复
//[StructLayout(LayoutKind.Sequential)]
[Serializable]
public struct RECORD
{
public long date;
public long open;
public long hight;
public long low;
public long close;
public long travl;
public long traca;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public byte[] unuse;
}
RECORD reco;
private void button3_Click(object sender, EventArgs e)
{
string file = "0000001.day";
if (File.Exists(file))
{
FileStream fs = File.Open(file, FileMode.Open);
readdrec(fs);
fs.Close();
}
else
{
//printf(_T("Error..............."));
}
}
int readdrec(FileStream fs)
{
float fn;
unsafe
{
//int sizetoread = sizeof(RECORD);
//byte[] buffer = new byte[sizetoread];
//fs.Read(buffer, 0, sizetoread);
try
{
BinaryFormatter bf = new BinaryFormatter();
reco = (RECORD)bf.Deserialize(fs);
fn = ((float)reco.open)/1000;
MessageBox.Show(fs.ToString());
//......等等。。。
}
catch (Exception) { }

}
return 0;
}
美丽海洋 2008-02-16
  • 打赏
  • 举报
回复
c代码看懂了 就是不会C#
songshp39 2008-02-16
  • 打赏
  • 举报
回复
沙发

111,092

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧