contrib/mul/mbl/mbl_read_str.cxx
Go to the documentation of this file.
00001 // This is mul/mbl/mbl_read_str.cxx
00002 #include "mbl_read_str.h"
00003 //:
00004 // \file
00005 // \brief Ask String question.
00006 //
00007 //  Copyright: (C) 1994 Victoria University of Manchester
00008 
00009 #include <vcl_cstdio.h>
00010 #include <vcl_cstring.h>
00011 
00012 char* mbl_read_str(char *reply, int max_str_len, const char *q_str, const char *default_str)
00013 {
00014   char *new_reply = new char[max_str_len];
00015 
00016   vcl_printf("%s (%s) :",q_str,default_str);
00017 
00018   // Now read in a line of text
00019   if (!vcl_fgets(new_reply,max_str_len,stdin))
00020   {
00021     vcl_strncpy(reply,"*** Error from std::fgets() ***",max_str_len);
00022   }
00023   else if (new_reply[0]=='\n')
00024   {
00025     if (reply!=default_str)
00026       vcl_strncpy(reply,default_str,max_str_len);
00027   }
00028   else
00029   {
00030     int i=0;
00031     while (new_reply[i]!='\n')  i++;
00032     new_reply[i]='\0';
00033     // Replace the '\n' by a '\0' to remove it from end of new_reply
00034     vcl_strncpy(reply,new_reply,max_str_len);
00035   }
00036 
00037   delete [] new_reply;
00038   return reply;
00039 }
00040