File: mbl_read_str.cxx

package info (click to toggle)
vxl 1.17.0.dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 153,280 kB
  • ctags: 105,123
  • sloc: cpp: 747,420; ansic: 209,130; fortran: 34,230; lisp: 14,915; sh: 6,187; python: 5,856; makefile: 340; perl: 294; xml: 160
file content (40 lines) | stat: -rw-r--r-- 923 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// This is mul/mbl/mbl_read_str.cxx
#include "mbl_read_str.h"
//:
// \file
// \brief Ask String question.
//
//  Copyright: (C) 1994 Victoria University of Manchester

#include <vcl_cstdio.h>
#include <vcl_cstring.h>

char* mbl_read_str(char *reply, int max_str_len, const char *q_str, const char *default_str)
{
  char *new_reply = new char[max_str_len];

  vcl_printf("%s (%s) :",q_str,default_str);

  // Now read in a line of text
  if (!vcl_fgets(new_reply,max_str_len,stdin))
  {
    vcl_strncpy(reply,"*** Error from std::fgets() ***",max_str_len);
  }
  else if (new_reply[0]=='\n')
  {
    if (reply!=default_str)
      vcl_strncpy(reply,default_str,max_str_len);
  }
  else
  {
    int i=0;
    while (new_reply[i]!='\n')  i++;
    new_reply[i]='\0';
    // Replace the '\n' by a '\0' to remove it from end of new_reply
    vcl_strncpy(reply,new_reply,max_str_len);
  }

  delete [] new_reply;
  return reply;
}