Need help with Fortran homework -- Error: Invalid form of PROGRAM statement

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
4 replies · 3K views
suezxc6
Messages
11
Reaction score
0
Homework Statement
im trying to compile this program but i get this error

print*, cap= one (m:m)------------------------------Capitalize:
1
Error: Invalid form of PROGRAM statement at (1)
Relevant Equations
,
Fortran:
program Lab5A
      implicit none
      ! This program introduces Fortran string handling capabilities

      character*26 upper, lower, name, cap
      character str*2, one*1
      integer from, to, i, m

      lower = "abcdefghijklmnopqrstuvwxyz"
      upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
      name = "loool"

      ! ---------------------------------------------------Substrings:
      do i = 1, 5
         print*, "The string we are studying is: ", name
         print*, "Enter two integers ..."
         read*, from, to
         print*, name(from:to)
      end do

      ! ---------------------------------------------------Pattern:
      do i = 1, 5
         print*, "Enter any 2-character string (e.g. enter er) ..."
         read 5, str
         print*, index(name,str)
      end do
    5 format(A)

      ! ---------------------------------------------------Capitalize:
      do i = 1, len(name)
         one = name(i:i)
         m = index(lower,one)
         if (m .ne. 0) then
            one = upper (m:m)
         end if
         cap(i:i) = one
       end do
       print*, cap
   
       end
 
Last edited by a moderator:
on Phys.org
suezxc6 said:
Homework Statement:: I am trying to compile this program but i get this error

print*, cap= one (m:m)------------------------------Capitalize:
1
Error: Invalid form of PROGRAM statement at (1)
Relevant Equations:: ,

Fortran:
program Lab5A
      implicit none
      ! This program introduces Fortran string handling capabilities

      character*26 upper, lower, name, cap
      character str*2, one*1
      integer from, to, i, m

      lower = "abcdefghijklmnopqrstuvwxyz"
      upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
      name = "loool"

      ! ---------------------------------------------------Substrings:
      do i = 1, 5
         print*, "The string we are studying is: ", name
         print*, "Enter two integers ..."
         read*, from, to
         print*, name(from:to)
      end do

      ! ---------------------------------------------------Pattern:
      do i = 1, 5
         print*, "Enter any 2-character string (e.g. enter er) ..."
         read 5, str
         print*, index(name,str)
      end do
    5 format(A)

      ! ---------------------------------------------------Capitalize:
      do i = 1, len(name)
         one = name(i:i)
         m = index(lower,one)
         if (m .ne. 0) then
            one = upper (m:m)
         end if
         cap(i:i) = one
       end do
       print*, cap
 
       end
The error you show doesn't agree with the code you listed. The compiler is complaining about this line print*, cap= one (m:m)------------------------------Capitalize:
but there's no line that looks like that in your code. My suggestion is to save your code, and then recompile, and see if you get the same error again.
 
  • Like
Likes   Reactions: sysprog
i did just as you requested and still got this
 

Attachments

  • s.png
    s.png
    8.6 KB · Views: 299
Last edited by a moderator:
Here's what I would try -- remove all spaces from the label 5 in your format statement.
Fortran:
    do i = 1, 5
        print*, "Enter any 2-character string (e.g. enter er) ..."
        read 5, str 
        print*, index(name,str)
    end do 
5 format(A)
Older Fortran versions were very picky about what could appear in a given column. Perhaps your compiler is complaining that the label for your format statement isn't in the right place.

You could also get rid of the format statement completely.
Fortran:
read *, str
 
  • Like
Likes   Reactions: sysprog
Are you sure that you can put an entire array name in the print statement of line 38? It might just want a single ellement. In older FORTRANs one had to loop some way through the elements. The loop can be included in the print statement like:
WRITE(*,*) (x(i), y(i), i=1, n)
 
  • Like
Likes   Reactions: sysprog