Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Compiler errors &引用;“不可分类声明”;引用函数时_Compiler Errors_Fortran - Fatal编程技术网

Compiler errors &引用;“不可分类声明”;引用函数时

Compiler errors &引用;“不可分类声明”;引用函数时,compiler-errors,fortran,Compiler Errors,Fortran,我正在学习函数中的伪参数和局部变量 我在书中使用的一个练习是编写一个程序,要求用户输入他们的名字和姓氏,然后将这些名字连接在一起并打印出全名。代码如下: PROGRAM name_test IMPLICIT NONE ! Declare variables CHARACTER(LEN=12) :: first, last CHARACTER(LEN=30), EXTERNAL :: full_name ! 1. Ask for first name a

我正在学习函数中的伪参数和局部变量

我在书中使用的一个练习是编写一个程序,要求用户输入他们的名字和姓氏,然后将这些名字连接在一起并打印出全名。代码如下:

PROGRAM name_test
    IMPLICIT NONE

    ! Declare variables
    CHARACTER(LEN=12) :: first, last
    CHARACTER(LEN=30), EXTERNAL :: full_name

    ! 1. Ask for first name and family name, then read them
    PRINT *, "Please enter your first name"
    READ *, first
    PRINT *, "Please enter your family name"
    READ *, last

    ! 2. Join names together
    full_name(first, last)

    ! 3. Print welcome message
    PRINT *, "Welcome ", full_name(first, last)

END PROGRAM name_test

CHARACTER(LEN=*) FUNCTION full_name(first_name, last_name)
    IMPLICIT NONE

    ! Function which joins 2 names to form a full name

    ! Dummy argument declarations
    CHARACTER(LEN=*), INTENT(IN) :: first_name, last_name

    ! Local variables
    CHARACTER(LEN=LEN(first_name)) :: new_first_name
    CHARACTER(LEN=LEN(last_name)) :: new_last_name

    ! Use ADJUSTL to remove redundant leading blanks
    new_first_name = ADJUSTL(first_name)
    new_last_name = ADJUSTL(last_name)

    ! Join names
    full_name = TRIM(new_first_name)//" "//new_last_name

END FUNCTION full_name
当我尝试编译时,它出现了一个错误,涉及第15行的函数调用:

full_name(first, last)
这是编译错误:

Error: Unclassifiable statement at (1)

您在第full_name(first,last)行上有一个错误-虽然它给了我语法错误,但可能只是编译器不同

您正在使用的函数返回一个值,因此您可以在print语句中直接使用它。在此之前不需要使用它,即使在此之前使用过,您仍然需要将其值(它返回的值)分配给类似的值

字符串=全名(第一个,最后一个)

不管怎样,我把它缩短了一点,给你

  program name_test
  implicit none

  character(len=12) :: first, last
  character(len=30), external :: full_name

  write(*,'("Please enter your first name : ",\)'); read(*,*)first
  write(*,'("Please enter your last name  : ",\)'); read(*,*)last
  write(*,'("Welcome ",A)')full_name(first,last)

  end program name_test


  function full_name(first,last)
  implicit none

  character(len=*) :: first, last
  character(len=30) :: full_name

  full_name = trim(adjustl(first))//" "//trim(adjustl(last))
  end function full_name