We help IT Professionals succeed at work.

Fortran - count the number of character

How do I write a FORTRAN 77 Program to read in any character from the user, and the system will count the number of character entered by the user?
Comment
Watch Question

Commented:
Something along these lines:
character*100 myline
read *, myline
print *, character*(*) myline
CERTIFIED EXPERT

Commented:
The parameter IOSTAT may be the key to acomplish that. Please see the following example:

        character*1 c
        k=0
        do while (.true.)
                read (*,*,iostat=i,end=10) c
                k=k+1
        end do
10    continue
        stop
        end

OR

        character*1 c
        k=0
        do while (.true.)
                read (*,*,iostat=i) c
               if (i .ne. 0) goto 10
                k=k+1
        end do
10    continue
        stop
        end

Note: 'do while ... end do' is not f77 standard; the 'do n=1,nmax ... end do' can be used instead.

Author

Commented:
Hi CJ S and Waynezhu,

  The program given by u doesn't work!(I am using MS Fortran 77). For the answer given by CJ S, syntax error occurs.  I am still finding alternative ways to achieve it

Regards,
Tee

Commented:
on which line?

Author

Commented:
Syntax error on last line

Commented:
What is current status? Can you show latest code that works?

Commented:
?

Commented:
C     FORTRAN 77

     character*40 name
     integer i,k

C      .....

       
     read (*,'(A40)') name

C       --------------------------------------
C       Search last not equal space symbol
C       example - '12345 6789' will be = 10

     do 10,i=40,1,-1
 10     if (name(i:i).ne.' ') goto 20

 20     k=i

C      write (*,*) name (1:k)
     write (*,*) ' # of input with spaces =', k


C       --------------------------------------    
C       Calculate numbers of not equal space symbols
C       example - '12345 6789' will be = 9

     k=0
     do 30,i=1,40
 30     if (name(i:i).ne.' ') k=k+1
     
C     write (*,*) name
     write (*,*) ' # of input without spaces =', k

C     ...

     end

Commented:
pgob

I've rejected your proposed answer as Experts Exchange holds an experiment to work without the answer button.

See:        http://www.experts-exchange.com/jsp/communityNews.jsp
Paragraph: Site Update for Wednesday, November 06, 2002

By this rejection the Asker will be notified by mail and hopefully he will take his responsibility to finalize the question or post an additional comment.
The Asker sees a button beside every post which says "Accept This Comment As Answer" (including rejected answers) -- so if he/she thinks yours is the best, you'll be awarded the points and the grade.

modulo

Community Support Moderator
Experts Exchange
No comment has been added lately.
To cleanup this TA, I will recommend to moderators that this question is:

*** Answered by: waynezhu ***

Please leave any comments here within the next seven days, or finalize the question if you own it
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
peterchen
EE Volunteer
PAQ'd and points NOT refunded.  See comments on From: teesimhui
Date: 09/25/2001 03:11AM PST indicates neither program works.

SunBow's and pBob's responses link together and neither times were they selected.

SpideyMod
Community Support Moderator @Experts Exchange