How can I search for a specific phrase in a sentence using FORTRAN?

In summary, the code needs to read the text file and search for the word "good boy" and then store the position number of "good boy" in the text file.
  • #1
manjurul
4
0
Most of the examples here are given from the following book,

Michael Kupferschmid, "Classical Fortran: Programming for Engineering and Scientific Applications", Taylor & Francis Group, 2009

The generalized form of READ command is as follows,

READ (unit, format) list

where, the value of 'unit' could be any value ranging from 0-99 or star symbol '*'. Both 5 or * means standard-in (usually keyboards). If the 'format' is *, then the format will be according to the compiler default. However if 'format' is not * , then it will refer the label of the FORMAT statement. Note that the FORMAT statement is used to specify exactly how the input/output will be. The 'list' is the list of variables to be read.

Any of the commands are used to read an input for variable A,

PHP:
READ (*,*) A

and

PHP:
READ *,A

are same commands. It means the program will take an input from standard-in (usually keyboard).
 
Last edited:
Technology news on Phys.org
  • #2
For output the general forms are as follows,

WRITE (unit, format) listfor the details of 'unit', 'format' and 'list' see above.
 
Last edited:
  • #3
HI,
I want to write some results in my fortran code. The way i want to get it written is the values should be written on the same line and NOT on the next line and so on...How can i achieve it bu using the write command?
 
  • #4
Hi Nisha,

You need to use FORMAT statement and it is not difficult to do that.. you can see the following link to do that,

http://fortranmanjurul.blogspot.com/

also test the following code and see how FORMAT statement works

PHP:
         PROGRAM readonce
         REAL*8 X/1.23D0/, Y/53.0D0/
         J=37
         WRITE(6,10) J,X,Y
 10      FORMAT(1X,I3,T7,'X=',T9,F5.2,3X,T17,D8.2)
         STOP
         END PROGRAM readonce

Hope this solves your problem
 
Last edited:
  • #5
I need to write a code which can read the following sentence from a text file,

"I know that he is a good boy!".

After reading it, the code has to search if the word "good boy" is there or not. Also the position number of "good boy" in the sentence (i.e. after how many character)

Kindly anyone help me
 

1. What is FORTRAN and why is it important for beginners?

FORTRAN (short for Formula Translation) is a programming language commonly used for scientific and engineering applications. It is important for beginners because it is a relatively simple and easy-to-learn language, making it a good starting point for those interested in programming.

2. What makes FORTRAN different from other programming languages?

FORTRAN is specifically designed for scientific and mathematical applications, making it particularly efficient for handling complex calculations. It also has a straightforward syntax and is known for its speed and reliability.

3. Are there any resources for beginners to learn FORTRAN?

Yes, there are many online tutorials, books, and courses available for beginners to learn FORTRAN. Some popular resources include the official FORTRAN website, online coding platforms like Codeacademy, and various YouTube tutorials.

4. What are some common mistakes beginners make when writing FORTRAN code?

Some common mistakes include using incorrect syntax, not properly declaring variables, and not understanding the logic behind mathematical operations. It is important for beginners to thoroughly review their code and seek help from experienced programmers if needed.

5. Can FORTRAN be used for more than just scientific applications?

Yes, while FORTRAN is primarily used for scientific and engineering purposes, it can also be used for other applications such as database management, financial analysis, and creating web applications. Its versatility and speed make it a useful language in many different industries.

Similar threads

  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
6
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
8
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
2K
  • Programming and Computer Science
Replies
8
Views
879
  • Programming and Computer Science
Replies
22
Views
4K
  • Programming and Computer Science
Replies
1
Views
3K
Back
Top