- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
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
- Balises:
- Intel® Fortran Compiler
Lien copié
2 Réponses
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
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.
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
Thanks a lot Steve, it works!!!

Répondre
Options du sujet
- S'abonner au fil RSS
- Marquer le sujet comme nouveau
- Marquer le sujet comme lu
- Placer ce Sujet en tête de liste pour l'utilisateur actuel
- Marquer
- S'abonner
- Page imprimable