next up previous contents
Next: Point on a circle Up: Concatenate Names Previous: Concatenate Names

Solution

    PROGRAM Names
     IMPLICIT NONE

     CHARACTER(LEN=10) :: Xian, Family
     CHARACTER(LEN=21) :: Full
     INTEGER, PARAMETER :: lower_to_upper = IACHAR('A')-IACHAR('a')
     INTEGER i, pos

      Xian = "         "
      Family = "         "
      PRINT*, "Type in the first name"
      READ*, Xian
      PRINT*, "Type in the last name"
      READ*, Family

      ! First letter
      IF (Xian(1:1) .GE. 'a' .AND. Xian(1:1) .LE. 'z') THEN
        Full(1:1) = ACHAR(IACHAR(Xian(1:1))+lower_to_upper)
      ELSE
        Full(1:1) = Xian(1:1)
      END IF

      ! rest of first name
      DO i = 2, LEN_TRIM(Xian)
       IF (Xian(i:i) .GE. 'A' .AND. Xian(i:i) .LE. 'Z') THEN
        Full(i:i) = ACHAR(IACHAR(Xian(i:i))-lower_to_upper)
       ELSE
        Full(i:i) = Xian(i:i)
       END IF
      END DO

      ! Inter name space
      Full(i:i) = ' ' 
      pos = i + 1

      ! First letter
      IF (Family(pos:pos).GE.'a' .AND. Family(pos:pos).LE.'z') THEN
       Full(pos:pos) = ACHAR(IACHAR(Family(pos:pos))+lower_to_upper)
      ELSE
       Full(pos:pos) = Family(1:1)
      END IF

      pos = pos + 1

      ! rest of first name
      DO i = 2, LEN_TRIM(Family)
       IF (Family(i:i) .GE. 'A' .AND. Family(i:i) .LE. 'Z') THEN
        Full(pos+i:pos+i)=ACHAR(IACHAR(Family(i:i))-lower_to_upper)
       ELSE
        Full(pos+i:pos+i)=Family(i:i)
       END IF
      END DO

      PRINT*, TRIM(Full)

    END PROGRAM Names


next up previous contents
Next: Point on a circle Up: Concatenate Names Previous: Concatenate Names

Adam Marshall ©University of Liverpool, 1996
Fri Dec 6 14:10:26 GMT 1996