Toxa Kniotee
Toxa Kniotee

Reputation: 55

Extract a single character from a Fortran string

I need a program to convert from base a to base b, where base a and b could be from 2 to 36.

My idea was to use strings as the numbers, convert to base 10 as an intermediary and then convert from base 10 to base b. As I'm new on Fortran I can't understand quite the functions and substring, right now I'm getting the error:

intToChar  = cadena(int,int)
1
Error: Unclassifiable statement at (1)

On the next code:

CHARACTER FUNCTION intToChar(int)
    IMPLICIT NONE
    INTEGER, INTENT(IN) :: int
    CHARACTER(LEN = 36) :: cadena

    cadena = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"

    intToChar    = cadena(int,int)
END FUNCTION intToChar

I'm following this tutorial

Upvotes: 3

Views: 1473

Answers (1)

casey
casey

Reputation: 6915

The syntax to select a substring from a character variable uses a colon :, not a comma ,. The line the compiler is complaining about should be:

intToChar = cadena(int:int)

This will select the single character as position int from cadena, which appears to be your goal with that function.

Upvotes: 3

Related Questions