sources/Main.c
/**
 * Function to read string dynamically from the input stream symbol-by-symbol.
 * \param[in] The input stream
 * \param[out] lastError Error code
 * \return A string from the input
 */
Function to read string dynamically from the input stream symbol-by-symbol.
\param[in] The input stream
\param[out] lastError Error code
\return A string from the input
Function to read string dynamically from the input stream symbol - by - symbol . \ param [ in ] The input stream \ param [ out ] lastError Error code \ return A string from the input
char *ReadLine(FILE *in, error_t *lastError)
{
  char *buffer = NULL;
  char *line = (char *) malloc(sizeof(char));
  int tmp;
  int index = 0;
  tmp = fgetc(in);
  if (tmp == EOF)
  {
    free(line);
    return NULL;
  }
  if (line == NULL) 
  {
    *lastError = ERR_NOT_ENOUGH_MEMORY;
    while (tmp != '\n')
    {
      tmp = (char) fgetc(in);
      if (tmp == EOF)
      {
        break;
      }
    }
    return NULL;
  }
  line[index] = (char) tmp;
  while (line[index] != '\n' && line[index] != (char) EOF)
  {
    buffer = (char *) realloc(line, sizeof(char) * (++index + 1));
    if (buffer == NULL)
    {
      *lastError = ERR_NOT_ENOUGH_MEMORY;
      tmp = (char) fgetc(in);
      while (tmp != '\n' && tmp != EOF && tmp != '\0')
        tmp = (char) fgetc(in);
      return NULL;
    }
    line = buffer;
    line[index] = (char) fgetc(in);
  }
  if (line[index] == '\n' || line[index] == (char) EOF)
  {
    line[index] = '\0';
  }
  return line;
}
char * ReadLine ( FILE * in , error_t * lastError ) { char * buffer = NULL ; char * line = ( char * ) malloc ( sizeof ( char ) ) ; int tmp ; int index = 0 ; tmp = fgetc ( in ) ; if ( tmp == EOF ) { free ( line ) ; return NULL ; } if ( line == NULL ) { * lastError = ERR_NOT_ENOUGH_MEMORY ; while ( tmp != ' \n ' ) { tmp = ( char ) fgetc ( in ) ; if ( tmp == EOF ) { break ; } } return NULL ; } line [ index ] = ( char ) tmp ; while ( line [ index ] != ' \n ' && line [ index ] != ( char ) EOF ) { buffer = ( char * ) realloc ( line , sizeof ( char ) * ( ++ index + 1 ) ) ; if ( buffer == NULL ) { * lastError = ERR_NOT_ENOUGH_MEMORY ; tmp = ( char ) fgetc ( in ) ; while ( tmp != ' \n ' && tmp != EOF && tmp != ' \0 ' ) tmp = ( char ) fgetc ( in ) ; return NULL ; } line = buffer ; line [ index ] = ( char ) fgetc ( in ) ; } if ( line [ index ] == ' \n ' || line [ index ] == ( char ) EOF ) { line [ index ] = ' \0 ' ; } return line ; }
Function to read string dynamically from the input stream symbol-by-symbol.
Function to read string dynamically from the input stream symbol - by - symbol .
/* checking malloc */