Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7805825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:20:05+00:00 2026-06-02T02:20:05+00:00

I need to use the C library in a C# project. How can I

  • 0

I need to use the C library in a C# project. How can I do?

To be more specific: for reasons of efficiency I need to use the strtod function to extract double values from a string (like this “9.63074,9.63074 -5.55708e-006 0 ,0 1477.78”). If you have suggestions about how to optimize this operation do not be shy, but the main question remains that specified by title.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T02:20:06+00:00Added an answer on June 2, 2026 at 2:20 am

    I think it very unlikely that p/invoking to strtod would be more efficient than a pure C# solution. There is an overhead in managed/unmanaged transitions and I would think that would be significant for something as trivial as strtod. Myself I would use a C# tokenizer, combined with double.Parse.

    The simplest C# tokenizer is String.Split() which yields this routine:

    static List<double> getValues(string str)
    {
        List<double> list = new List<double>();
        foreach (string item in str.Split(default(Char[]), StringSplitOptions.RemoveEmptyEntries))
            list.Add(double.Parse(item));
        return list;
    }
    

    However, since I enjoy p/invoke, here’s how you would call strtod from C#, bearing in mind that I recommend you don’t use this approach in real code.

    [DllImport(@"msvcrt.dll", CallingConvention=CallingConvention.Cdecl)]
    static extern double strtod(IntPtr str, ref IntPtr endptr);
    

    You can call it like this:

    IntPtr str = Marshal.StringToHGlobalAnsi(inputStr);
    IntPtr endptr = IntPtr.Zero;
    double val = strtod(str, ref endptr);
    Marshal.FreeHGlobal(str);
    

    I’m passing the string as an IntPtr because you would be calling strtod repeatedly to walk across the entire buffer. I didn’t show that here, but if you are going to make any use of endptr then you need to do it as I illustrate.

    Of course, to use strtod remotely effectively you need to gain access to the errno global variable. The very fact that you need to deal with a global variable should be warning enough that here be dragons. What’s more, the error reporting offered through errno is exceedingly limited. However, if you want it, here it is:

    [DllImport(@"msvcrt.dll", CallingConvention = CallingConvention.Cdecl)]
    static extern int _get_errno();
    

    One final point. Your suggested input string is

    "9.63074,9.63074 -5.55708e-006 0 ,0 1477.78"
    

    but strtod won’t tokenize that because of the spurious commas.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to use class Matrix4x4 from some 3rd party library, and I need
I am relatively new to C++ and need to use a library for the
I need to use the current library name explicitly in a CL program. CHGVAR
I need to use the mongo-storm library and Clojars doesn't have it . So
I need to use two extension methods SqlCommandExtensions & SqlConnectionExtensions http://msdn.microsoft.com/en-us/library/microsoft.practices.enterpriselibrary.windowsazure.transientfaulthandling.sqlazure(v=pandp.50).aspx Here they say
I have developed a simple library in Ruby and need to use this in
In my library I use HostingEnvironment.MapPath for my web application. But I need to
I have a library I am trying to use. To install it I need
So, I need use this event so I can navigate trought blog posts. I
I'm building a widget library for our mobile project. The question is to use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.