ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm trying to compile a Fortran program, but am having trouble converting from int to char. I looked into the ICHAR procedure offered with the GNU compiler, but I haven't figured out how to use it since my code is within a block data section. Does anyone have an idea how to change these lines so that I don't get the error? (or is there a compiler option?)
Code:
gfortran -c -I./included_dir -Werror -Wtabs -fall-intrinsics myfortranfile.f
myfortranfile.f:107.15:
DATA NUM/'0 ','1 ','2 ','3 ','4 ','5 ','6 ',
1
Error: Incompatible types in assignment at (1), CHARACTER(1) to INTEGER(4)
myfortranfile.f:106.17:
DATA LEVEL/'+ ','/ ',' ','* ','0 ','B '/
1
Error: Incompatible types in assignment at (1), CHARACTER(1) to INTEGER(4)
make: *** [myfortranfile.o] Error 1
The ichar function returns the ASCII code of the characters. To convert from int to char and vice versa you have to use internal file I/O, that is:
Code:
READ(STRING, '(I5)') IVAR ! converts a numeric string to integer
WRITE(STRING, '(I5)') IVAR ! converts an integer to a string
but you can do that when assigning values in a DATA statement. You have to respect the type of the variable and eventually do the conversion inside the code when you need them. Also from the second line of your error message:
Code:
DATA LEVEL/'+ ','/ ',' ','* ','0 ','B '/
I don't really understand how do you want to convert symbols to integer, unless you really want their ASCII code, in which case I have misunderstood your post.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.