×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Integer to char

Integer to char

Integer to char

(OP)
Is there a way to convert a integer to a character
And if there is a way what is that way

Thanks

Christian

RE: Integer to char

A simple way may be:
define a char (or array of char) and an Integer.
put it into an equivalence Statement. (watch the size of the variables)

Probably there is a function which will do it, but my "Fortran" - experience is about 10 years ago.


hnd
hasso55@yahoo.com
 
 

RE: Integer to char

Unfortunely it isn't working
By assinging the integer value to character I get the ASCII code
So the Result of the program is a 'A'
      Program test
       integer a
       character(10) c
       a=65
       c=a
       write(*,*) c   !Result is  'A'
      end

But thanks anyway

RE: Integer to char

************************************************************************
*                                                                      
* Routine name: ITOS                                                                                                                    
************************************************************************
*                                                                      
* Description:                                                         
*
*    THIS FUNCTION TRANSLATE INTEGER NUMBER TO STRING                  
*                                                                      
* Argument:                                                            
*                                                                      
*    NUM    INTEGER*4  IN  - THE NUMBER TO TRANSLATE                   
*    LENGTH INTEGER*4  IN  - THE EXPECTED LENGTH OF THE TRANSLATED     
*                            STRING                                    
*                                                                      
* return status:                                                       
*                                                                      
*   CHARACTER*(*) - THE TRANSLATED STRING                              
*                                                                      
************************************************************************

    CHARACTER*(*) FUNCTION ITOS(NUM,LENGTH,BLANKS)
    IMPLICIT NONE

********************    D E F I N I T I O N S  ******************

    integer*4     num,
    1        length

    logical     blanks

    integer*4     i,
    1        int

    character*80     str
 
    logical     put_zero

    intrinsic     mod,
    1        char,
    1        ichar

********************    P R O C E D U R E  ******************

    put_zero = .true.
    if (%loc(blanks) .ne. 0) put_zero = .not. blanks

    str = '  '

    int = num
    do i=0,length-1
          str(length-i:length-i) = char(mod(int,10)+ichar('0'))
      int = int / 10
      if ((.not. put_zero) .and. (int .eq. 0)) goto 10
    enddo

10    continue

    if (str .eq. '  ') str(length:length) = '0'

    itos = str(1:length)
              
    END

RE: Integer to char

C     A SIMPLER WAY  ....
C     EXAMPLE
      CHARACTER * 10  A
      I = 1234
      WRITE(A,'(I4)') I
C     CHECK :
      WRITE(*,'(A4)') A
      END

RE: Integer to char

I think Mr Anderson presents a classic implementation here.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close