MED fichier
MED2cstring.c
Aller à la documentation de ce fichier.
1 /* This file is part of MED.
2  *
3  * COPYRIGHT (C) 1999 - 2016 EDF R&D, CEA/DEN
4  * MED is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * MED is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with MED. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 
19 #include <stdlib.h>
20 #include "med_config.h"
21 #include "med_outils.h"
22 
23 /*
24  * - Nom de la fonction _MED2cstring
25  * - Description : convertit une chaine de caracteres FORTRAN en
26  * nouvelle chaine de caracteres C
27  * (crée une copie de chaine C en supprimant
28  * les blancs terminaux et
29  * terminant par le caractère \0)
30  * - Parametres :
31  * - chaine (IN) : la chaine FORTRAN
32  * - longueur (IN) : longueur de la chaine FORTRAN
33  * - Resultat : la nouvelle chaine C en cas de succes, NULL sinon
34  */
35 char *_MED2cstring(char *chaine, int longueur)
36 {
37  char *nouvelle;
38  char *temoin;
39  int long_reelle = longueur;
40  int i;
41  med_err _ret =0;
42 
43  if ( longueur < 0 ) return NULL;
44 
45  temoin = chaine+longueur-1;
46  while (*temoin == ' ' && (temoin > chaine) )
47  {
48  temoin --;
49  long_reelle--;
50  }
51  if ( *temoin == ' ') long_reelle = 0;
52 
53  if ((nouvelle = (char *) malloc(sizeof(char)*(long_reelle+1))) == NULL) {
55  return NULL;
56  }
57 
58  /* +1 en trop mais caractère écrasé par le caractère null */
59  for (i=0;i<long_reelle+1 ;i++)
60  *(nouvelle+i) = *(chaine+i);
61  *(nouvelle+long_reelle) = '\0';
62 
63  return nouvelle;
64 }
herr_t med_err
Definition: med.h:310
#define MED_ERR_NOTNULL
Definition: med_err.h:33
#define MED_ERR_NAME_MSG
Definition: med_err.h:190
char * _MED2cstring(char *chaine, int longueur)
Definition: MED2cstring.c:35
#define MED_ERR_API
Definition: med_err.h:108
#define MED_ERR_(rt, r1, r2, r3)
Definition: med_utils.h:158