- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I need to convert a character string to an integer. The string looks like:
112###### (where # ara blank spaces) and is defined as follows:
character crecy*13
Can anyone help me?
Thanks
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is a common question to those new to Fortran. The Fortran way of doing this is not to call a routine, as in other languages, but to use a special form of I/O statements called "internal I/O". With internal I/O, you specify a character variable in place of the unit number. You can do formatted or list-directed internal I/O. (You can even use character arrays, in which eash array element is considered a "record".)
So in your case you would want something like:
READ (CRECY, '(BN,I13)') intvar
Some people would use list-directed (format *) here, but I recommend against it because list-directed is too permissive in what it will accept. If you know that the input is always a well-formed integer, you can use:
READ (CRECY, *) intvar
instead.
So in your case you would want something like:
READ (CRECY, '(BN,I13)') intvar
Some people would use list-directed (format *) here, but I recommend against it because list-directed is too permissive in what it will accept. If you know that the input is always a well-formed integer, you can use:
READ (CRECY, *) intvar
instead.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks a lot Steve, it works!!!

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page