Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!fu-berlin.de!uni-berlin.de!not-for-mail From: jt@toerring.de (Jens Thoms Toerring) Newsgroups: comp.lang.c++ Subject: Re: reading from a temp file Date: 28 Jun 2011 09:55:53 GMT Organization: Freie Universitaet Berlin Lines: 79 Message-ID: <96tmp9FvidU1@mid.uni-berlin.de> References: <96ti78FuacU2@mid.individual.net> X-Trace: news.uni-berlin.de j/rNLC7RNAUcF5lKrxedDwSQFpJhjPGdU88FBcp63c4g42 X-Orig-Path: not-for-mail User-Agent: tin/1.9.3-20080506 ("Dalintober") (UNIX) (Linux/2.6.30-1-amd64 (x86_64)) Xref: x330-a1.tempe.blueboxinc.net comp.lang.c++:7196 Ian Collins 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