Need Help with Fortran compiler errors

In summary: In addition, you need to show the exact error message. If you need help with the forum, I suggest you read the forum rules. In particular, read the section about code tags.
  • #1
suezxc6
11
0
Summary:: so I am trying to compile this program and i keep on getting "Unterminated character constant beginning at (1)" and "invalid character in name" at the months section. what do i have to change to fix it?

thanks

Fortran:
program Lab6

implicit none
character*9 month

integer monthNum, pos
character*108 months
months = "January       February March       April     &

                  &May             June         July           August  &

                  &SeptemberOctober November December "
print*, "Enter the month name"

read*, month
pos = index(months,month)

if (pos .eq. 0) then

print*, "The month is invalid"

else

monthNum = pos/9 + 1

! process day

print*, month, " is month #", monthNum

print*, "now process day"

end if
stop

end
<Moderator's note: code tags added>
 
Last edited by a moderator:
Physics news on Phys.org
  • #2
I added code tags to your post, but you will need to repost to get the spacing correct.

I see nothing wrong, assuming that the blank lines 18 and 20 are not really present. Which compiler are you using?
 
  • #3
GNU. And there are no blank lines present. At line 17 i get "Unterminated character constant beginning at (1)" then at 19 and 21 i get "invalid character in name".
 
  • #4
I have no problem compiling it with gfortran. Can you show the compile command you are using?
 
  • #5
You may have an invisible character, such as ESC, in the source code. How that happened and how you get rid of it I don't know.
 
  • #6
a.png

this is what it looks like.
 
  • #7
The file extension needs to be f90, since you re using that variant of Fortran.
 
  • Like
Likes berkeman and jedishrfu
  • #8
Thanks, it works!
I'm new to fortran and this is all still pretty confusing. Is there by any chance a fortran for dummies book i could buy online somewhere? With lectures being canceled I am going to need all the help i can get
 
  • #9
ok sorry yall. its me again and i need help with this exercise.
I have to write a program that will output the astrological signs for given birthdays. It will have to read a date in a given format and after a simplified validity check it has to determine the corresponding astrological sign. So if i wrote September 21 it has to output virgo. I'm getting a lot of errors and also having a hard time with the part i italicized.

program Lab6
implicit none

character*1 reply

do
print*, "Do you want to convert a date, Y or N?"
read*, reply
if (reply .eq. "N" .or. reply .eq. "n") exit
print*, "process a date"

character*9 month
integer monthNum, pos, day

character*36 months1 / "January February March April "
character*36 months2 / "May June July August "
character*36 months3 / "SeptemberOctober November December "

character*108 months

integer lastDay(12) / 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 /

integer splitDay(12) / 19,18,20,19,20,20,22,22,22,22,21,21 /

character*11 astroSign(12) / "Capricorn", "Aquarius",
x "Pisces", "Aries", "Taurus", "Gemini", "Cancer",
x "Leo", "Virgo", "Libra", "Scorpio", "Sagittarius" /

months = months1 // months2 // months3

print*, "Enter the month name"
read*, month

pos = index (months, month)
if (pos .eq. 0) then
print*, "The month is invalid"
else
monthNum = pos/9 + 1
monthNum = mod(monthNum, 12)+1
print*, "Enter the day"
read*, day
if (invalid day for the given month) then
print*, "The day is invalid"
else
adjust monthNum to align with astrological sign
print*, "The astrological sign is: ", astroSign(monthNum)
end if
end if

end do
stop
end
 
  • #10
I suggest you make an array of months as you did for the astrological signs. This will make string comparison easier and you can also more easily convert the month into a number.

Think of how you would do things yourself, with a calendar you are not familiar with. First, you would check to see if the month is part of the list of valid months, then if the day is a valid number for that month. I let you figure out how you would then figure out the corresponding star sign. This is the basis of algorithms: decompose the big task into smaller tasks.
 
  • #12
@suezxc6 Please use code tags (>_ Inline code in the dropdown menu) when posting code:
Screen Shot 2020-03-20 at 13.06.51.png
I have also moved the thread to the homework forum.
 
  • #13
FORTRAN can be very space and column dependent. You need to use the code tags (see the '</>' tag at the top of the edit window) to keep those exactly like your program code or it will not be possible to get help.
 

1. Why am I getting a "syntax error" when compiling my Fortran code?

There could be several reasons for a syntax error when compiling Fortran code. One common reason is a missing or misplaced punctuation mark, such as a comma or a parenthesis. Another possibility is using a reserved keyword or variable name. It is important to carefully check your code for any spelling or syntax errors.

2. How do I fix a "segmentation fault" error when running my Fortran program?

A segmentation fault error occurs when a program tries to access memory that it does not have permission to access. This can happen due to a variety of reasons, such as trying to access an uninitialized variable or going out of bounds in an array. To fix this error, it is important to carefully check your code for any memory access errors and make sure all variables are properly initialized.

3. What does the "undefined reference" error mean when compiling Fortran code?

The "undefined reference" error means that the compiler cannot find a definition for a function or variable that is being used in your code. This could be due to a missing library or module that contains the definition, or a misspelling in the function or variable name. Make sure all necessary libraries and modules are included and that all function and variable names are spelled correctly.

4. How do I resolve a "file not found" error when compiling my Fortran program?

A "file not found" error means that the compiler cannot locate a file that is needed for compiling your program. This could be due to a misspelled file name or an incorrect file path. Make sure all file names and paths are correct and that the necessary files are included in the correct location.

5. What is the best way to debug Fortran compiler errors?

The best way to debug Fortran compiler errors is to carefully read the error messages and try to identify the specific line of code that is causing the error. It can also be helpful to use a debugger tool or print statements to track the flow of your program and identify any potential issues. Additionally, seeking help from experienced Fortran programmers or consulting online resources can also aid in resolving compiler errors.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
  • Computing and Technology
Replies
2
Views
949
  • Engineering and Comp Sci Homework Help
Replies
7
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Programming and Computer Science
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Programming and Computer Science
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
3K
  • Programming and Computer Science
Replies
4
Views
4K
Back
Top