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

  • Home
  • SEARCH
  • 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 537485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:55:54+00:00 2026-05-13T09:55:54+00:00

I have the following FORTRAN: SUBROUTINE MYSUB(MYPARAM) !DEC$ ATTRIBUTES DLLEXPORT::SetPaths CHARACTER*50 MYPARAM WRITE(6, *)

  • 0

I have the following FORTRAN:

  SUBROUTINE MYSUB(MYPARAM)
  !DEC$ ATTRIBUTES DLLEXPORT::SetPaths

  CHARACTER*50 MYPARAM

  WRITE(6, *) MYPARAM

  END SUBROUTINE

Then I have the following in C#

class Program
{
    static void Main(string[] args)
    {
        StringBuilder sb = new StringBuilder(50);
        sb.Append(@"something");
        MYSUB(sb);

        Console.ReadLine();
    }

    [DllImport(@"myCode.dll", EntryPoint = "MYSUB")]
    public static extern void MYSUB(StringBuilder input);

}

However, the WRITE in my FORTRAN shows a bunch of junk after “something.” Looks like the string terminator is not being honored. Help!

  • 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-05-13T09:55:55+00:00Added an answer on May 13, 2026 at 9:55 am

    Strings are the trickiest datatype to interchange between different languages.

    The basic Fortran string is fixed length, padded on the end with blanks. (Fortran now has variable length strings, but those would be harder to interchange.) The intrinsic “trim” is provided to suppress trailing blanks; “len_trim” to provide the length less trailing blanks.

    C flags the end of a string with a null character.

    I don’t know how C# handles strings — an internal variable for the length?? a terminator??

    But Fortran isn’t going to understand C#’s representation, it will just see the full length of the string, as declared, including, in this case, uninitialized memory. The best solution is probably to initialize the remainder of the string to blanks in C#.

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

Sidebar

Related Questions

I have the following FORTRAN SUBROUTINE SETPATHS(INPUT) !DEC$ ATTRIBUTES DLLEXPORT::SetPaths CHARACTER*20 INPUT CHARACTER*20 DIRECTORY
I have following class. In this, Iris is another class with some attributes. public
I have following seed input data: Payperiod start: Dec 3rd Payperiod end: Dec 16
I have the following FORTRAN code which I need to convert to C or
I have stumbled upon the following F77 yacc grammar: http://yaxx.cvs.sourceforge.net/viewvc/yaxx/yaxx/fortran/fortran.y?revision=1.3&view=markup . How can I
I have following class public abstract class Rule { protected Rule() { Nodes =
I have following situation: class TextBoxCellControl : TextBox, IDataGridViewCellControl class EnhancedTextBoxCellControl : Panel, IDataGridViewCell
I have following code: <div class='parent'> <div class='left-child'></div> <div class=right-child></div> </div> What I want
I have following setup. from django.db import models from django.contrib.auth.models import User class Event(models.Model):
I have numbers outputted from a FORTRAN program in the following format: 0.12961924D+01 How

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.