Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #7196
| From | jt@toerring.de (Jens Thoms Toerring) |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: reading from a temp file |
| Date | 2011-06-28 09:55 +0000 |
| Organization | Freie Universitaet Berlin |
| Message-ID | <96tmp9FvidU1@mid.uni-berlin.de> (permalink) |
| References | <iuc3me$nam$2@reader1.panix.com> <96ti78FuacU2@mid.individual.net> |
Ian Collins <ian-news@hotmail.com> wrote:
> On 06/28/11 08:34 PM, Ruben Safir wrote:
> > any clue why this isn't retrieving the contents of the temp file
> >
> > Question Deck::create_question(WINDOW* menu_win, std::ostream&os ,std::istream&in ){
> >
> > char default_editor[20000] = "vi ";
> > char * editor;
> > char tmp[4096];
> > char path[] = "/tmp/fileXXXXXX";
> Why don't you use strings?
> > int fd;
> > fd = mkstemp(path);
> > editor = getenv("EDITOR");
> > if (editor == NULL){
> > editor = default_editor;
> > }
> >
> > strcat(editor, path);
Also note that if the 'EDITOR' environment variable should be
set you're now trying to write into memory belonging to what-
ever returned the environment string. Definitely not a good
idea - while getenv() unfortunately returns a 'char *' and
not a 'char const *' (which would make this mistake impossible)
it's not meant as allowing you to modify that string (or, worse,
write past its trailing '\0').
> > char quest_prompt[] = "Edit Your Question";
> > .....
> > std::string input_q, input_a;
> > while( ( c=wgetch(quest_win) ) ){
What's 'quest_win'? There's no definition before. Did you mean
'menu_win' instead?
> > if ( (c == 10) ){
> > def_prog_mode();
> > endwin();
> What are these?
I suspect something related to (n)curses.
> > system(editor);
> > reset_prog_mode();
> and this?
> > __gnu_cxx::stdio_filebuf< char> tmpfile_buf(fd, std::ios::binary|std::ios::app);
> What's one of those?
> > std::istream is(&tmpfile_buf);
I suspect a highly system dependent attempt to obtain an input
stream from a file descriptor...
> > is.seekg(0, std::ios::beg);
> > while(is){
What should set 'is' to 0? Shouldn't you check for 'is.eof()'
and/or 'is.fail()'?
> > is.read( tmp, 4096);
> > std::cerr<< "What did we read"<< tmp<< std::endl;
> > input_q = tmp;
> > }
> > tmpfile_buf.close();
> > break;
> > }
> > }
> > remove(path);
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
reading from a temp file Ruben Safir <ruben@mrbrklyn.com> - 2011-06-28 08:34 +0000
Re: reading from a temp file Ian Collins <ian-news@hotmail.com> - 2011-06-28 20:37 +1200
Re: reading from a temp file jt@toerring.de (Jens Thoms Toerring) - 2011-06-28 09:55 +0000
Re: reading from a temp file Ruben Safir <ruben@mrbrklyn.com> - 2011-06-28 12:32 +0000
Re: reading from a temp file jt@toerring.de (Jens Thoms Toerring) - 2011-06-28 13:54 +0000
Re: reading from a temp file Ruben Safir <mrbrklyn@panix.com> - 2011-07-01 05:14 +0000
Re: reading from a temp file Michael DOUBEZ <michael.doubez@free.fr> - 2011-07-01 00:54 -0700
Re: reading from a temp file Michael DOUBEZ <michael.doubez@free.fr> - 2011-07-01 01:20 -0700
Re: reading from a temp file Ruben Safir <mrbrklyn@panix.com> - 2011-07-02 00:47 +0000
csiph-web