Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
26749 Discussions

How to transport character variable from Fortran to C without transiton

youn__kihang
Novice
117 Views

Hello developers,

 

I have some question related transporting chracter variable from Fortran to C.
Here are my codes:

# In Fortran
CHARACTER URL*128
URL='http://***.**.***.**/url/something.php?inf=some&tm=200001011200'
WRITE(URL(49:59),'(A10)') YYYYMMDDHH
CALL URLOPEN(IU, URL)

# In C
urlopen(int *ret, char* url) {   
printf("%s \n", url);}

 # Result
'http://***.**.***.**/url/somethine.php?inf=some&tm=200001011200'                                    #7777END

One odd thing is that it is okay in character length under 128(127,126,..).
Is there any problem to think about in the current situation? Is there a problem if the char length in C exceeds 128?
Please let me know if there is the way to use a longer length character because the length of URL may increase.

0 Kudos
3 Replies
GVautier
New Contributor II
117 Views

C strings are null terminated, so add a char(0) at the end of your fortran string.

There is no limit for C string length.

youn__kihang
Novice
117 Views

Hi Vautier,

Thank you for your help.
I understand what you are answering but I don't know how to fix this because I am not be good at C programming enough.
Additionally I have one more question to fix my problem.

The rest of C code is below:
urlopen(int *ret, char* url)
{  
    char *prul;
    printf("%s \n", url);
    purl = _fcdtocp(url);
    handle = url_fopen(purl, "r");
}

In the case that url is "http://some_url                                    #7777END", url_fopen process does not successed.
Please let me know how to modify this purl or url string?
ex1) purl = _fcdtocp(url(0:nlength-2))
ex2) CHARACTER  URL(0:128)
       URL="http://***.**.***.**/url/something.php?inf=some&tm=200001011200"
       URL(0)=" "
ex3) or something


Thank you,
Kihang

GVautier
New Contributor II
117 Views

In the fortran code, add //char(0) at the end of the url= statement.

Nothing to do on C side.

Reply