OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
get_line.c
Go to the documentation of this file.
1 #include <string.h>
2 #include <stdio.h>
3 
4 char *get_line(char* str, int nchar, FILE *stream, int enc)
5 /*******************************************************************
6 
7  s_parse
8 
9  purpose: similar to fgets, read a line in which does not begin
10  with a special comment character, remove any newline and
11  return the line
12 
13  Returns type: char * the pointer to the line storage or NULL
14  if an error
15 
16  Parameters: (in calling order)
17  Type Name I/O Description
18  ---- ---- --- -----------
19  char* str O array to fill with line
20  int nchar I limit on # char to read
21  FILE * stream I input file id
22  int enc I comment character such as
23  # ...
24 
25  Modification history:
26  Programmer Date Description of change
27  ---------- ---- ---------------------
28  W. Robinson 14-Mar-1995 Original development
29 
30  *******************************************************************/ {
31  char *ptr;
32 
33  /*
34  * read in lines until the start character is not the comment char
35  */
36  do {
37  if (fgets(str, nchar, stream) == NULL)
38  return NULL;
39  } while (*str == enc);
40 
41  /*
42  * remove any ending newline that can be left by the fgets routine
43  */
44  if ((ptr = strchr(str, '\n')) != NULL)
45  *ptr = 0;
46 
47  /*
48  * and exit
49  */
50  return str;
51 }
#define NULL
Definition: decode_rs.h:63
const char * str
Definition: l1c_msi.cpp:35
char * get_line(char *str, int nchar, FILE *stream, int enc)
Definition: get_line.c:4