How to convert this c code to C# - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

How to convert this c code to C#

vipulgondaliavipulgondalia Posts: 19Member
Hi friends,
I am an newbie to C#.NET. I had one program in which i am copying one DBF file to one buffer named BUFI and then getting some information like no. of fields/records/headersize etc. In C language, I used to get this information directly like :

fields = ((*((short *)(bufi+8)))-32)/32;
recs = *((long *)(bufi+4));
recsz = *((short *)(bufi+10));
headsz = *((short *)(bufi+8));

How can i get information using C#. Thanks in advance.

Comments

  • heileheile Posts: 7Member
    : Hi friends,
    : I am an newbie to C#.NET. I had one program in which i am copying one DBF file to one buffer named BUFI and then getting some information like no. of fields/records/headersize etc. In C language, I used to get this information directly like :
    :
    : fields = ((*((short *)(bufi+8)))-32)/32;
    : recs = *((long *)(bufi+4));
    : recsz = *((short *)(bufi+10));
    : headsz = *((short *)(bufi+8));
    :
    : How can i get information using C#. Thanks in advance.
    :

    This may sound like a stupid question, so sorry in advance, but have you tried to compile this code yet? From what I have read, C/C++ code maps pretty well to C#( with a few exceptions i.e. keyword, packages, ...).

    I am little confused what you are trying to do. What it appears to me you are doing is, using pointer dereferencing, trying to get the contents of an array(bufi) at certain indexes.

    If may help if you either post or e-mail me the entire c file and I see what I can do.

    BTW, Concerning your quest for C# info, there are many sites that can help you. I would start with MSDN then try codeproject, gotdotnet, here maybe, and if all else fails you can try googling (C + C/C++ + C# + tutorials) and see what it brings up.

    Hope this helps :)
  • ing_gigioing_gigio Posts: 31Member
    : : Hi friends,
    : : I am an newbie to C#.NET. I had one program in which i am copying one DBF file to one buffer named BUFI and then getting some information like no. of fields/records/headersize etc. In C language, I used to get this information directly like :
    : :
    : : fields = ((*((short *)(bufi+8)))-32)/32;
    : : recs = *((long *)(bufi+4));
    : : recsz = *((short *)(bufi+10));
    : : headsz = *((short *)(bufi+8));
    : :
    : : How can i get information using C#. Thanks in advance.
    : :
    :
    : This may sound like a stupid question, so sorry in advance, but have you tried to compile this code yet? From what I have read, C/C++ code maps pretty well to C#( with a few exceptions i.e. keyword, packages, ...).
    :
    : I am little confused what you are trying to do. What it appears to me you are doing is, using pointer dereferencing, trying to get the contents of an array(bufi) at certain indexes.
    :
    : If may help if you either post or e-mail me the entire c file and I see what I can do.
    :
    : BTW, Concerning your quest for C# info, there are many sites that can help you. I would start with MSDN then try codeproject, gotdotnet, here maybe, and if all else fails you can try googling (C + C/C++ + C# + tutorials) and see what it brings up.
    :
    : Hope this helps :)
    :

    I don't think this code could compile under .NET for the simple reason that in .NET there's not the concept of pointer. What's get closer to it it's a reference but its syntax it's different.

    As someone already suggested, it would be easier to help u with the whole code or a lil deeper explaination
  • BaldusariusBaldusarius Posts: 162Member
    : : : Hi friends,
    : : : I am an newbie to C#.NET. I had one program in which i am copying one DBF file to one buffer named BUFI and then getting some information like no. of fields/records/headersize etc. In C language, I used to get this information directly like :
    : : :
    : : : fields = ((*((short *)(bufi+8)))-32)/32;
    : : : recs = *((long *)(bufi+4));
    : : : recsz = *((short *)(bufi+10));
    : : : headsz = *((short *)(bufi+8));
    : : :
    : : : How can i get information using C#. Thanks in advance.
    : : :
    : :
    : : This may sound like a stupid question, so sorry in advance, but have you tried to compile this code yet? From what I have read, C/C++ code maps pretty well to C#( with a few exceptions i.e. keyword, packages, ...).
    : :
    : : I am little confused what you are trying to do. What it appears to me you are doing is, using pointer dereferencing, trying to get the contents of an array(bufi) at certain indexes.
    : :
    : : If may help if you either post or e-mail me the entire c file and I see what I can do.
    : :
    : : BTW, Concerning your quest for C# info, there are many sites that can help you. I would start with MSDN then try codeproject, gotdotnet, here maybe, and if all else fails you can try googling (C + C/C++ + C# + tutorials) and see what it brings up.
    : :
    : : Hope this helps :)
    : :
    :
    : I don't think this code could compile under .NET for the simple reason that in .NET there's not the concept of pointer. What's get closer to it it's a reference but its syntax it's different.
    :
    : As someone already suggested, it would be easier to help u with the whole code or a lil deeper explaination
    :

    Actually, C# allows the use of pointers in blocks of code marked "unsafe". There will only be a miniscule number of cases they're actually needed, though.
Sign In or Register to comment.