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

Click For Summary
The discussion centers on a Fortran programming error related to an "Invalid form of PROGRAM statement." The user encounters a compilation issue with a specific line in their code, which does not match the error message received. Suggestions include removing spaces from the format statement label and ensuring proper column placement, as older Fortran versions are sensitive to formatting. Additionally, it's advised to consider eliminating the format statement entirely and using a different method to print arrays. The conversation emphasizes the importance of adhering to syntax rules in Fortran to avoid such compilation errors.
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:
Physics news 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 sysprog
i did just as you requested and still got this
 

Attachments

  • s.png
    s.png
    8.6 KB · Views: 274
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 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 sysprog

Similar threads

  • · Replies 12 ·
Replies
12
Views
4K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 6 ·
Replies
6
Views
5K
Replies
5
Views
3K
  • · Replies 3 ·
Replies
3
Views
7K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 12 ·
Replies
12
Views
10K